#!/usr/bin/perl -w use strict; pipe READER,WRITER or die; my @output; if (my $pid = fork) { # parent, close the WRITER and read from READER close WRITER; while() { chomp; push(@output,$_); print "adding $_ to \@output\n"; } # parent now has the system() output in @output, # as well as the line from the child's print() } else { # child, dup WRITER to STDOUT and close WRITER, then # exec() your system call open(STDOUT,">&WRITER"); close WRITER; print STDOUT "This is the child running ls\n"; exec("/bin/ls"); }