use POSIX qw(:sys_wait_h); sub REAPER { 1 until (-1 == waitpid(-1, WNOHANG)); $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER;