http://www.perlmonks.org?node_id=971117


in reply to reg. expr. multiple substitutions

Use a hash:

my %subs = ( tag1 => 'subst1', tag2 => 'subst2', ... ); my $pattern = join('|', keys %subs); $str =~ s/($pattern)/$subs{$1}/g;

It would be a good idea to simplify $pattern if there is some common pattern to the tags.

By the way, you need to use the g modifier to replace all occurrences of each tag if it can occur more than once in the string, also if you are substituting each tag separately.