use v5.8.0; my $stderr; eval { open(local *STDERR, '>', \$stderr); warn("foo\n"); # no output die("bar\n"); # no output }; print STDERR ("\$stderr: $stderr"); # $stderr: foo die($@) if $@; # bar