- or download this
$string =~ s/(a|b)/$map{ $1 }/g;
- or download this
$pattern = join '|', map quotemeta, keys %map;
$string =~ s/($pattern)/$map{ $1 }/go; # /o only if the pattern never
+ changes
- or download this
use Regex::PreSuf;
my $pattern= presuf(keys %map);
$string =~ s/($pattern)/$map{ $1 }/go;
- or download this
$pattern = join '|', map quotemeta, sort { length($b) <=> length($a) }
+ keys %map;
- or download this
$pattern = join '|', map quotemeta, sort { $b cmp $a } keys %map;