in reply to perl one-liner

Why do you need perl for that?

echo "hello" > file
(and it works on Win32 and UNIX!)

Unless I'm misreading the question...

Update: If this is just an exercise to use truncate...
perl -i -e 'truncate <>,0; print "HELLO";' mytest

Update: trying to figure out the right way to do this...

Update^3:
perl -i -pe 'truncate $ARGV[0], 0; print "Hello"; last' test.pl

do note that if the file doesn't exist or is empty already, this won't work.