use strict; use warnings; use Benchmark; my @matchlist = qw( this that these those some other too); my $string = 'here we have a typical sentance which has a match near the othr end'; my $bigregex = join '|', map quotemeta($_), @matchlist; my $byhandre = 'th(is|at|ese|ose)|some|other|too'; timethese(shift, { 'Index', 'SimpleIndex', 'm// loop', 'Match', 'BigRE', 'BigRE', 'OptRE', 'ByHand', } ); sub SimpleIndex { for (@matchlist) { return 1 if(index($string, $_) != $[-1 ); } 0; } sub Match { for (@matchlist) { return 1 if( $string =~ /$_/io ); } 0; } sub BigRE { return 1 if( $string =~ /$bigregex/io ); 0; } sub ByHand { return 1 if( $string =~ /$byhandre/io ); 0; }