my $pid = open3('<&STDIN', \*CHLD_OUT, \*CHLD_ERR, "some_shell_expression"); while() { # do something with that command's output } my $err = ; # may block - better use select here waitpid $pid, 0; if ( $? ) { warn $_[0] . ($? == -1) ? "failed to execute: $!\n" : ($? & 127) ? sprintf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' : sprintf "child exited with value %d\n", $? >> 8; }