use POSIX; # ... if (!defined($pid=fork()) { # fork fails } elsif($pid) { # parent waitpid(-1, WNOHANG); # run code here } else { # child }