die("Cannot open /cdw/home_dir/s006258/MarketingDB/.") unless(opendir(DIR, "/cdw/home_dir/s006258/MarketingDB/")); #Print to new file die("Cannot open Log file to read from.") unless(open(FILES, ">List_of_files_changed.txt")); print "Reading from file\n"; #reading from file for my $file (readdir(DIR)) { if($file =~ /^append/) { print "$file\n"; $old=$_; s/^append/aPPend/; die "$_ already exists" if (-e $_); print "$old is old and $_ is new\n"; rename($old, $_) or die "Failed to rename\n"; } }