use strict; use warnings; use Benchmark qw(cmpthese); my @letters = ('A'..'Z','a'..'z'); sub searchword { my $len = shift; return join '', map { @letters[int rand(@letters)] } 1..$len; } my @words = map { searchword(3+rand(20)) } 1..300; my $strings_file = "list_of_strings_file"; open my $fh, ">", $strings_file or die "Couldn't write '$strings_file': $!"; print $fh "$_\n" for @words; close $fh; my $re = join '|', @words; cmpthese(100, { 'perl' => sub { open my $fh, "<", $^X or die "Couldn't open '$^X': $!"; my $content; sysread $fh, $content, 1e7 or die $!; close $fh; $content =~ /$re/; }, 'fgrep' => sub { system qw(grep -F -o -f), $strings_file, $^X; }, });