A couple of questions. First why do you "have to" chmod the file to be able to have anyone do anything to it before you do anything. Presumably if your CGI can open the file for write, it can write to it without chmoding it. Secondly, any reason that you're not using the perl built-in chmod function?