... if (!$pid) { # if we get here, the fork succeeded, but the exec (likely) failed... my $err = $@ ? $@ : "unknown error"; # return error, and exit child print STDERR "Error: Could not execute $command: $err"; POSIX::_exit($!); } ...