use Fcntl qw(:seek); # save STDERR filehandle open(my $ORIGSTDERR, ">&", STDERR); # create temporary filehandle to catch STDERR open(my $CATCHERR, "+>", undef) or die("cannot open temp file :: $!"); open(STDERR, ">&", $CATCHERR); # redirection ## STDERR is captured here ## open(PIPE, '-|', $somecommand, $arg1, $arg2, $argN, $filename); ... # restore STDERR filehandle open(STDERR, ">&", $ORIGSTDERR); # read captured STDERR from temporary filehandle seek($CATCHERR, 0, SEEK_SET); print "From CATCHERR: $_" while <$CATCHERR>; close($CATCHERR); #### use IPC::Exe; ## exports exe() & bg() use Fcntl qw(:seek); # create temporary filehandle to catch STDERR open(my $CATCHERR, "+>", undef) or die("cannot open temp file :: $!"); # $cmd is a CODE reference to exec $somecommand #my $cmd = exe sub { open(STDERR, ">&", $CATCHERR) }, $somecommand, @args, $filename; my $cmd = exe sub { open(STDERR, ">&", $CATCHERR) }, 'perl', '-le', 'print "From STDOUT"; print STDERR "From STDERR"; exit 33'; my @pid_and_err = $cmd->(); # do it! my $pid = shift(@pid_and_err); # only one PID $? = pop(@pid_and_err); # last array item is $CHILD_ERROR print "PID was $pid\n"; print "Exit status was ", ($? >> 8), "\n"; # read captured STDERR from temporary filehandle seek($CATCHERR, 0, SEEK_SET); print "From CATCHERR: $_" while <$CATCHERR>; close($CATCHERR); __END__ Output: From STDOUT PID was 6914 Exit status was 33 From CATCHERR: From STDERR