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