use strict; use warnings; use 5.010; my $child_pid = fork; $| = 1; if (!defined $child_pid) { say "**My error**: couldn't fork: $!"; } if ($child_pid) { #then in parent say "in parent..."; sleep 1; } else { #then in child open my $OUTFILE, '>', 'data1.txt' or die "**My error: couldn't open data1.txt: $!"; my $old = select $OUTFILE; $| = 1; select $old; for (1 .. 10) { say $OUTFILE $_; sleep 2; } close $OUTFILE; } #### --output:-- $ perl 1perl.pl in parent... $ cat data1.txt 1 2 $