use Proc::Queue size => 5; for (1..20) { # you don't want to fork here!!! do_task($_); 1 while wait != -1; }