foreach my $thr (@threads) { if ( $thr->is_joinable() ) { $thr->join(); } }