foreach( threads->list() ) { $_->join(); } #### use threads::shared; ## at the top ... my $running : shared = 0; ## before the main loop ... sleep 1 while $running; ## after the main loop in-place of the join loop sub deleteDevice($) { ++$running; .... # as now --$running; }