in reply to related to threads

Ah ok. The following should solve your problem, it is tested and works on my machine. Be sure to use a recent version of threads so that 'threads::running' and 'threads::joinable' are implemented.
while (@dirs_to_ftp) { my $dir= shift @dirs_to_ftp; startthread($dir); while (threads->list(threads::running)>=2) { sleep 1; } foreach my $thr (threads->list(threads::joinable)) { $thr->join(); } } foreach my $thr (threads->list()) { $thr->join(); }