#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $words = do{ local( @ARGV, $/ ) = 'words.txt'; <> }; our @words = split ' ', $words; our $P //= 0.01; our @toLookFor = map { rand() > $P ? () : do { my $w = $_; my $p = int( rand length()-1 ); $w =~ s[.{$p}\K.][.]; $w; }; } @words; printf "Looking for %d terms amongst %d words\n", scalar @toLookFor, scalar @words; cmpthese 1, { a => q[ for my $re ( @toLookFor ) { m[^$re$] #and print "a:$re :: $_" for @words; } ], b => q[ $words =~ m[\b($_)\b] #and print "b:$_ :: $1" for @toLookFor; ], } __END__ C:\test>junk42 Looking for 1846 terms amongst 178691 words s/iter a b a 85.2 -- -95% b 3.94 2065% -- C:\test>junk42 -P=0.02 Looking for 3564 terms amongst 178691 words s/iter a b a 166 -- -95% b 7.83 2022% --