use constant LIMIT => 1000; sub pause { my $delay = shift; select '','','', $delay; } sub workerSub { my ($workerQueue,$outputQueue) = @_; while (my $computer = $workerQueue->dequeue()) { ## SSH command retrieving grep results and processing pause( 0.01 ) while $outputQueue->pending > LIMIT; $outputQueue->enqueue($results); } }