#!/usr/bin/perl use strict; use warnings; use File::Spec (); my $dir = '/cdw/home_dir/s006258/MarketingDB'; my $log = 'List_of_files_changed.txt'; opendir(local *DIR, $dir) or die("Cannot open $dir.\n"); open(local *FILES, '>', $log) or die("Cannot open output file $log.\n"); while (defined(my $file = $filereaddir(DIR))) { next unless $file =~ /^append/; my $old = my $new = $file; $new =~ s/^append/aPPend/; $old = File::Spec->catfile($dir, $old); $new = File::Spec->catfile($dir, $new); die("Unable to rename $old: $new already exists.\n") if -e $new; rename($old, $new) or die("Unable to rename $old: $!\n"); print FILES ("$old renamed to $new\n"); }