use Benchmark qw/:all/; sub regex { return ($_[1] =~ m/^$_[0]/) ? 1 : 0; } sub index_func { return (index($_[1], $_[0]) == 0) ? 1 : 0; } cmpthese ( 500000, { 'regex match' => sub { regex('abbr', 'abbreviation') or die }, 'index match' => sub { index_func('abbr', 'abbreviation') or die }, 'regex miss' => sub { regex('anna', 'abbreviation') and die }, 'index miss' => sub { index_func('anna', 'abbreviation') and die }, }); __END__ Rate regex match regex miss index miss index match regex match 680272/s -- -13% -36% -38% regex miss 781250/s 15% -- -27% -29% index miss 1068376/s 57% 37% -- -3% index match 1101322/s 62% 41% 3% --