my $pid = fork() // die "fork: $!"; if( $pid ){ print "forked: i am shelling out\n"; spawn(); print "after shelling out.\n"; } print "I am now waiting for background process.\n"; waitpid $pid, 0; print "done.\n"; sub spawn { my $pid = open(my $xx, "sleep 1 2>&1|") or die "fork: $!"; print "implicitly waiting for child...\n"; # close($xx); } #### print "before spawn\n"; spawn(); print "after spawn\n"; sub spawn { my $pid = open(my $xx, "sleep 3 2>&1|") or die "fork: $!"; print "implicitly waiting for child...\n"; # the proper way to wait for the command to exit: # close($xx); } # output: before spawn implicitly waiting for child... # sleep... after spawn