#!/usr/bin/perl use strict; use warnings; use Benchmark; undef $/; my $text = <>; # "progressive", "great", "interlacing", "really" and "wonder" are in the document my $words = q{ featuring | blossom | great | interlacing | really | linux | thought | wonder | progressive }; timethese(200, { lookahead5 => sub { 1 while $text =~ m{(?= [fbgrltwpi][elihorn][aoent][tsaludge][ustrlxger] )( $words )}gix; }, lookahead4 => sub { 1 while $text =~ m{(?= [fbgrltwpi][elihorn][aoent][tsaludge] )( $words )}gix; }, lookahead3 => sub { 1 while $text =~ m{(?= [fbgrltwpi][elihorn][aoent] )( $words )}gix; }, lookahead1 => sub { 1 while $text =~ m{(?= [fbgrltwpi] )( $words )}gix; }, nolookahead => sub { 1 while $text =~ m{( $words )}gix; }, });