How to modify HTML file with Perl: preserving lists and erasing all other tags [closed]

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="" 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>

Browse More Popular Posts

Leave a Comment