use Benchmark; my @letters = qw (A B C D E F); my $string = "AFTYUBEWTWECRTUTYIYTDDDDRYJURTHJTREEEEEFGSDFF" x 100; timethese(1000,{ match=>\&match,subst=>\&subst}); sub match{ my $str = $string; foreach (@letters) { my $count = 0; $count ++ while $str =~ /$_/g; # print "$_ : $count\n"; } } sub subst{ my $str = $string; foreach (@letters){ my $count = $str =~ s/$_//g; # print "$_ : $count\n"; } } output: Benchmark: timing 1000 iterations of match, subst... match: 10 wallclock secs ( 2.52 usr + 0.01 sys = 2.53 CPU) @ 395.26/s (n=1000) subst: 2 wallclock secs ( 1.88 usr + 0.01 sys = 1.89 CPU) @ 529.10/s (n=1000)