#!/usr/bin/perl use POSIX ":sys_wait_h"; my $child = fork; if ($child) { # parent case my $res; while (not ($res = waitpid($child, WNOHANG))) { sleep 5; # check file list here # ... print "checking file list\n"; } if ($res == -1) { warn "fatal child error\n"; exit; } } else { # child case # insert job processing here print "job processing\n"; sleep 12; exit; # comment this out to see how many times the final print occurs if you don't exit." # child must explicitly exit otherwise both would continue executing this } print "Past the if\n";