use Proc::Queue size => 5, debug => 1; use POSIX ":sys_wait_h"; # imports WNOHANG foreach (1..20) { my $f=fork; (my child processes do stuff) exit 0; # stop a child process 1 while waitpid(-1, WNOHANG)>0; # reaps children }