open(FOO,">/temp/foo") || die $!; sub foo { local *STDOUT=*FOO; print "foo"; } #yes, this is supposedly to STDOUT foo; close(FOO);