#!/usr/bin/perl -w use strict; use diagnostics; use warnings; my $output; open my $oldout, ">&STDOUT" or die "Can't dup STDOUT: $!"; #open STDOUT, '>', "foo.out" or die "Can't redirect STDOUT: $!"; open STDOUT, '>',\$output or die "Can't redirect STDOUT: $!"; print "stdout 1\n"; open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!"; print "stdout 2\n"; print "\$output = \'$output\'\n";