while (-e $filename){ $filename.= '.new'; } # while being here, another script can create a file with # the same $filename, causing a bug... open(F, "> $filename");