my %children; for my $n ( 1..4 ) { my $child = fork; if ( !defined $child) { die "fork failed on $n: $!" } elsif ( $child == 0 ) { # this is what the child does: exec 'some', 'process', $n; } $children{$child} = $n; } while ( keys %children ) { my $reaped_pid = wait; if ( exists( $children{$reaped_pid} )) { checkerror_function( $children{$reaped_pid} ); delete $children{$reaped_pid}; } else { # if you get here, better study "perldoc perlipc" } }