## initialization my $old = 'abc'; my $new = 'xyz'; my %table; @table{split //, $old} = split //, $new; my $table_re = join '|', map quotemeta reverse sort keys %table; ## the deed my $string = 'abracadabra'; $string =~ s/($table_re)/$table{$1}/g;