### This is a non-runnable code fragment ### only to show a general idea of threads pulling work ### from a common input queue and putting results on a ### common output queue. use Threads::Queue; my @all_inputs; global data for all threads as read only ### Worker threads ##### my $thread_limit = 4; my @threads; push @threads, threads->create(sub{DoWork($workQueue, $doneQueue)}) for 1 .. $thread_limit; foreach my $input ( @all_inputs ) #init the work queue with all inputs { $workQueue->enqueue($input); } $workQueue->enqueue(undef) for 1 .. $thread_limit; #"work finished" markers #each thread will give up #when it sees an undef $workQueue->end(); $_->join() for @threads; #waits for all threads to finish! print "END of threading...\n"; #### Get results off of Queue my @results; while ($doneQueue->pending() && ($_ = $doneQueue->dequeue()) ) { push (@results, $_); #results are pointers to array (AoA) } sub DoWork { my ($workQueue, $doneQueue) = @_; while (my $input = $workQueue->dequeue()) { return unless defined ($input); #this ends this thread's job!! if ($input =~ m|/|) { $doneQueue -> enqueue([$input,'SKIPPING THIS ENTRY!']); next; } my $regex = get_regex_patterns ($input); $regex =~ s/\(|\)//g; #captured values not needed, only yes/no my @matches = grep{ m/$regex/ and $_ ne $input}@all_inputs; push (@matches,'') if @matches==0; $doneQueue -> enqueue([$call,@matches]); } }