sub worker_thread { while ( my $item = $processing_q -> dequeue() ) { # do stuff to $item } } for ( my $count = 0; $count < $nthreads; $count++ ) { my $thr = threads -> create ( \&worker_thread ); } $processing_q -> enqueue ( @server_list ); $processing_q -> end; foreach my $thread ( threads -> list() ) { $thread -> join(); }