#!perl -w use strict; use Benchmark qw/:all/; my $result = timethese( -5, { index => sub { -1 != index 'fooabc123', '123' }, regex => sub { 'fooabc123' =~ /123/ } } ); cmpthese $result;