my %k = qw(l < g > & &); print "$_ to ".s/(&)amp;|&(l|g)t;/$k{$+}/reg.$/ for qw( & &lt; &gt; < > ); #### & to & &lt; to < &gt; to > < to < > to >