in reply to Checking for existing filename before renaming file

if (! -e $oldfile)
should read
if (! -e $_)
and
print "Could not rename $_ because $oldfile name already exists and ca +n not be overwritten\n";
should read print "Could not rename $oldfile to ${_}, because ${_} $oldfile already exists and can not be overwritten\n";

this was easy to debug, did you try to find out?
it helps to look at the variable-values...

hth

regards,
tomte