in reply to subroutines which forks?

The parent can't do two things at the same time, so some kind of central child management is required. You can limit the amount of knowledge the child manager has about the child creators by using callbacks.

my %children; sub forker1 { my $resource = ...; my $pid = ...; $children{$pid} = sub { print "forker1 child $pid exited with \$?=$?\n"; ... clean up $resource ... }; } sub forker2 { my $resource = ...; my $pid = ...; $children{$pid} = sub { print "forker2 child $pid exited with \$?=$?\n"; ... clean up $resource ... }; } ... forker1() for 1..3; forker2() for 1..3; while (keys(%children)) { my $pid = wait(); my $handler = delete($children{$pid}); $handler->() if $handler; }