foreach $key (@files) { push @threads, threads->new(\&Distribute, $ip, $host,$key) ; sleep(1); } while ( my $thread = shift @threads ) { $thread->join ; }