print "Should go to stdout.\n"; { local *STDOUT; open(STDOUT, ">afile.txt") or die "Couldn't open afile.txt: $!"; print "Should go to afile.txt\n"; } print "Should go to stdout.\n";