in reply to empty a file

If you are openning the file using the data and then writting new data to the file the simple way appears to me as follows
open IN, $file; #do what you need to do close IN; open OUT ">$file"; #print out the data close OUT;