use threads; use threads : shrared; foreach $host (@list_of_nodes) #we are connecting other PCs { threads->new(\&somefunction, $host); } (threads->list)[0]->join while threads->list;