#!perl use strict; use YAPE::Regex::Explain; my $str = '> milk & honey < < bill&ben >'; sub convert { my $input_stream = shift; return undef unless $input_stream; my %char_swap_hash = ( 1 => {OLD => '&[^(amp;)|(lt;)|(gt;)]', NEW => '&'}, # don't match legit '&' codes 2 => {OLD => '<', NEW => '<'}, 3 => {OLD => '>', NEW => '>'} ); $input_stream =~ s/$char_swap_hash{$_}{OLD}/$char_swap_hash{$_}{NEW}/g for keys %char_swap_hash; return $input_stream; } print YAPE::Regex::Explain->new('&[^(amp;)|(lt;)|(gt;)]')->explain; print convert($str),"\n";