in reply to Redirecting STDOUT, lexically scoped

Use local *STDERR:

my $out; print STDERR "before\n"; { local *STDERR; open STDERR, ">", \$out or die; print STDERR "during\n"; } print "after\n"; print "out: $out\n";

Output:

before after out: during