use strict; use warnings; require v5.8; my $hello1 = dupe_and_back(); my $hello2 = dupe_and_back(); print $hello1, $hello2; sub dupe_and_back { print "call to dupe_and_back\n"; my $output; open my $old_stdout, '>&=', \*STDOUT; close STDOUT; # Use of uninitialized value in open at the following line open STDOUT, '>', \$output; print "Hello world\n"; open STDOUT, '>&=', $old_stdout; return $output; } __END__ call to dupe_and_back call to dupe_and_back Use of uninitialized value in open at perlmonks.pl line 21. Hello world Hello world