use strict; use HTML::TokeParser::Simple; use Getopt::Std; my $Usage = "Usage: $0 -f word file.html > highlighted.html\n"; my %opts; ( getopts( 'f:', \%opts ) and $opts{f} and @ARGV == 1 ) or die $Usage; $opts{f} =~ tr/,/\|/; # This applies a regex substitution to the text part # and leaves the tags unmodified: while ( my $token = $p->get_token ) { if ( $token->is_text ) { $_ = $token->as_is; s{($opts{$f})}{$1}g; print; } else { print $token->as_is; } }