in reply to Cleaning file

Open it for read-write access (see perlopentut), seek to the beginning of the file, and then truncate.

(Of course were you on a real OS I'd suggest just cp /dev/null logfile, but I have no idea if Cygwin or using NUL: would accomplish the same thing).