#!/usr/bin/perl use strict; use warnings; use Benchmark 'cmpthese'; use List::Util 'first'; my @words = qw[ new old number start simple cross heavy die exit ]; my $string = join ' 0\4/f ', map( { rand $_ } 1 .. 60), map { $words[ rand @words ] } 1 .. 20; cmpthese (-3, { regexp => sub { return $string =~ /(new|old|number|start|simple|cross|heavy|die|exit)/i; }, use_index => sub { my $lcstring = lc $string; return first {index($lcstring, $_) > -1} @words; } }); __END__ Rate regexp use_index regexp 1084/s -- -96% use_index 29469/s 2619% --