use strict; use warnings; use Benchmark 'cmpthese'; undef $/; my $str = ; my @regexen = ( qr/foo/, qr/bar/ ); cmpthese(-2, { alternation => sub { my @m = $str =~ /(foo|bar)/g }, map => sub { my @m = map $str =~ /$_/g, @regexen }, loop => sub { my @m; push @m, $str =~ /$_/g for @regexen }, }); cmpthese(-2, { alt_s => sub { my $s2 = $str; $s2 =~ s/(foo|bar)//g }, loop_s => sub { my $s2 = $str; $s2 =~ s/$_//g for @regexen} }); __DATA__ This string contains foo and bar for fools and bards and I pity the foo who bars the way