open (FILE, ">$dir\\$file"); print FILE "this is text\n"; close FILE; or open (FILE, ">$dir\\$file"); *STDOUT = *FILE; print "this is text\n"; close FILE;