in reply to Regular expression question

First, you may want to look at a module like HTML::TextToHTML to take care of this particular type of example.

But for a general case, it would be something like this (the sort is to prevent short matches like f from usurping longer ones like foo)

my %repls = qw( < &lt; > &gt; foo bar bar foo f baz ); my $replstr = join '|', sort {length $b <=> length $a} keys %repls; s/$replstr/$repls{$&}/g;
Update: Shamelessly stole Abigail's initialization syntax

The PerlMonk tr/// Advocate