my $max_children = 10; # max number of children my $num_children = 0; # number we have now foreach $item (@items) { if( my $p = fork() ) { if ($num_children >= $max_children) { $dead_child = wait; $num_children--; } $num_children++; # child count } else { #do some sort of child processing last; # We want out of the loop } }