my $pid = open $fh, "-|"; if ($pid) { # parent here. Read from child. print "read from child: $_" while (<$fh>); wait; # ...for the child to finish. } else { # child here. STDOUT connected to parent $fh print while ; exit; # important, you don't want the child to execute # the statements after this block! } # parent continues ...