#!/usr/bin/perl -w use strict; use Benchmark qw( cmpthese ); chomp( my @words = ); push @words, map $_ x 100, @words; for( @words ) { if( s/ /0/g ) { s/0/ /; $_= reverse $_; } } seek DATA, 0, 0; push @words, grep chomp, ; @words= ( @words ) x 100; my $alpha = '[a-zA-Z]'; my $alnum = '[a-zA-Z0-9]'; my $qr= qr/^$alpha$alnum+$/; print 'Without /o:' => testsub(), $/, 'With /o:' => testsubo(), $/, 'With qr:' => testsubqr(), $/; cmpthese( -3, { '1//' => \&testsub, '1/o' => \&testsubo, '1qr' => \&testsubqr, '2//' => \&testsub, '2/o' => \&testsubo, '2qr' => \&testsubqr, }); sub testsub { my $count = 0; foreach (@words) { $count++ if(/^$alpha$alnum+$/); } return $count; } sub testsubo { my $count = 0; foreach (@words) { $count++ if(/^$alpha$alnum+$/o); } return $count; } sub testsubqr { my $count = 0; foreach (@words) { $count++ if $_ =~ $qr; } return $count; } __DATA__ include the real test data or code to generate it when posting benchmarks