sub foo { print "blah\n"; } my $OLDH; if ($to_file) { $OLDH = select MYFILE; } foo(); $OLDH and select $OLDH;