s/(.)/$hash{$1}/eg #### #!/usr/local/bin/perl use strict; use Benchmark; timethese( 1000000, { trchange => \&trchange, schange => \&schange, }); sub trchange { my $s = q{123 abc def a b a b a b}; $s =~ tr/a/A/; } sub schange { my $s = q{123 abc def a b a b a b}; $s =~ s/a/A/g; } # Benchmark: timing 1000000 iterations of schange, trchange... # schange: 21 wallclock secs (21.39 usr + 0.01 sys = 21.40 CPU) @ 46728.97/s (n=1000000) # trchange: 7 wallclock secs ( 6.41 usr + 0.01 sys = 6.42 CPU) @ 155763.24/s (n=1000000)