use strict; my $file; open($file, ">abc"); my $ret = fork; if ($ret) { print $file "log from parent\n"; sleep(5); close($file); } else { print $file "log from child\n"; }