# at the beginning of your code: use GenericSearch; # and then just ONE sub for all threads sub get_search { my $group = shift; GenericSearch::search($group, $maxHits, %searchTerms ); my @results = GenericSearch::getResults(); lock(@searchResults); push ( @searchResults, @results ); }