open(STDOUT, "| tee $outfile); print "whatever\n"; close(STDOUT);