open STDOUT, ">>$dir/TEST.NEW" or exit 1; open STDERR, ">>&STDOUT" or exit 2; flock STDOUT, LOCK_EX | LOCK_NB or exit 3; truncate STDOUT, 0; # delete everything from the file # The remainder of the program will be writing to an # empty file. close STDERR; close STDOUT;