use strict; use warnings; use MCE::Loop; use Time::HiRes 'time'; my @tokens = ('aaa'...'zzz'); my $start = time; sub build_regex { my ($token) = @_; chop $token; $token .= 'a'; } MCE::Loop->init( chunk_size => 1, max_workers => 4, ); my %result = mce_loop { my $token = $_; my $regex = build_regex($token); my @line_results = grep { $_ ne $token and /$regex/ } @tokens; MCE->gather( $token => \@line_results ) if @line_results; } @tokens; MCE::Loop->finish; printf "duration: %0.03f seconds\n", time - $start; print scalar(keys %result), "\n"; # 16900