# This forks implicitly my $child_pid = open my $child_fh, '-|'; if ( ! defined $child_pid ) { die "Can't fork: $!"; } if ( $child_pid ) { # parent print while ( <$child_fh> ); # this implicitly waits for the child close $child_fh or die "close on pipe failed: $!"; } else { # child # child's STDOUT is connected to the pipe print "Line 1\n"; print "Line 2\n"; exit; }