print "This goes to stdout\n"; { local *STDOUT; open STDOUT, '>/tmp/myoutput'; print "This gets redirected\n"; # more code here that prints stuff to stdout } print "Back to normal stdout\n";