foreach my $row (@$sections) { if (my $pid = fork) { $pids{$pid}++; } else { ... } } while (%pids) { my $pid = waitpid(-1, 0); delete $pids{$pid}; }