#!/usr/bin/perl -w use strict; #use warnings; use HTML::TokeParser; undef $/; print processHTML(); sub processHTML { my $tp = HTML::TokeParser->new(\$_[0]); my $return; while (my $token = $tp->get_token) { my $ttype = shift @{ $token }; if($ttype eq "S") # start tag? { $return .= $token->[3]; } elsif($ttype eq "T") # text? { $token->[0] =~ s/(perl)/\$1\<\/B\>/ig; $return .= $token->[0]; } elsif($ttype =~ /(?:C|D)/) # comment?declaration { $return .= $token->[0]; } elsif($ttype =~ /(?:E|PI)/) # end tag?process instrunction { $return .= $token->[1]; } } # endof while (my $token = $p->get_token) undef $tp; return $return; } __END__ This title contains Perl but does not get changed.

This is some text containing the term 'perl'.

  1. Unix
  2. Perl
  3. Linux

Notice how the term perl in the following link doesn't change, but the text does. Perlmonks.org