use strict; use warnings; use 5.010; my @lines = qw{ LINE1 LINE2 LINE3 LINE4 LINE5 }; my $pid = open my $INPUT_FROM_CHILD, '-|'; if (!defined $pid) { die "Couldn't fork: $!"; } if ($pid) { say 'parent: blocking until child sends some data...'; while (<$INPUT_FROM_CHILD>) { #line oriented reading chomp; say "parent: $_"; } waitpid($pid, 0); say "parent: child exited with status = $?"; say 'parent: exiting...'; } else { sleep 2; say $lines[int(rand(@lines))]; close $INPUT_FROM_CHILD; sleep 10; }