You can do this with HTML::Restrict
#!/usr/bin/env perl
use strict;
use warnings;
use HTML::Restrict;
my $hr = HTML::Restrict->new( rules => { li => [], ul => [] } );
my $html
= q[<body><b>hello</b> <img src="https://stackoverflow.com/questions/11188591/pic.jpg" alt="me" id="test" /><ul><li>one</li></ul></body>];
my $processed = $hr->process( $html );
print $processed;
The resulting output is:
hello <ul><li>one</li></ul>