#!perl -w
use HTML::TreeBuilder;
use diagnostics;
use strict;
my $root = HTML::TreeBuilder->new;
open(MYFILE, '<:utf8', 'sample_document.htm');
while () {$root->parse($_);}
$root->eof();
my @paras = $root->find_by_tag_name('p');
foreach my $h (@paras) {
foreach my $item_r ($h->content_refs_list) {
next if ref $$item_r;
### proprietary JavaScript/HMTL inserted with substitution
}
} # end foreach
print $root->as_HTML;