$ cat forked.pl #!/usr/bin/perl use strict; use warnings; open FH, ">forked.dat" or die $!; print FH "forked $$\n"; close FH; print STDERR "This should not appear ($$)\n"; $ perl -wle' if (my $pid = fork()) {  print "parent $$ forked $pid"; } elsif (defined $pid) {  close STDERR;  exec qw(perl forked.pl); } ' parent 29747 forked 29748 $ cat forked.dat forked 29748