use Benchmark; $string = 'aa ab ac ad ae af ' x 10000 . ' ff'; @string = split /\s/, $string; $regex = <<'CODE'; ®ex; sub regex { do{return 0 unless /^a[a-z]$/} for @string; return 1; } CODE $hash = <<'CODE'; $hash{$_}++ for aa..az; &hash; sub hash { do{return 0 unless defined $hash{$_}} for @string; return 1; } CODE timethese ( 100, { 'regex' => $regex, 'hash' => $hash } ); __END__ Benchmark: timing 100 iterations of hash, regex... hash: 21 wallclock secs (20.37 usr + 0.00 sys = 20.37 CPU) @ 4.91/s (n=100) regex: 45 wallclock secs (45.10 usr + 0.00 sys = 45.10 CPU) @ 2.22/s (n=100)