... my $pid = wait; if ($pid == $pid1) { ... $pid1 = -1; # indicate child1 has been reaped } ...