use Benchmark; timethese(10000, { 'Simple loop' => ' $text = "This is my test string"; %hash = qw(test text foo bar use loop the end); foreach $key (keys %hash) { $key = quotemeta $key; $text =~ s/$key/$hash{$key}/eg; } ', 'Alternation' => ' $text = "This is my test string"; %hash = qw(test text foo bar use loop the end); $regex = join("|", map(quotemeta, keys %hash)); $text =~ s/\b($regex)\b/$hash{$1}/eg; ', } ); Output: Benchmark: timing 100000 iterations of Alternation, Simple loop... Alternation: 5 wallclock secs ( 4.12 usr + 0.00 sys = 4.12 CPU) @ 24271.84/s (n=100000) Simple loop: 10 wallclock secs ( 9.72 usr + 0.00 sys = 9.72 CPU) @ 10288.07/s (n=100000)