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);