my $text = "foo"; sub SUBSTR { my $c = substr $text, 0, 1; return ( $c eq "*" or $c eq " " or $c eq "\t" or $c eq "\r" or $c eq "\n" ); } sub REGEX { return ($text =~ m/^\*/ || $text =~ m/^\s+/); } use Benchmark; timethese(5000000, { substr => \&SUBSTR, regex => \®EX }) __END__ Benchmark: timing 5000000 iterations of regex, substr... regex: 2 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 4672897.20/s (n=5000000) substr: 1 wallclock secs ( 1.38 usr + 0.00 sys = 1.38 CPU) @ 3623188.41/s (n=5000000)