*FOO=*STDOUT; #Save it somehow open(STDOUT,">>outputfile") || die $!; sub foo { print "foo bar"; } foo; close(STDOUT); *STDOUT=*FOO;