# first the indentation does not help you read this. # we indent to help identify blocks of code like: if ($this) { # do stuff } else { # do other stuff } # end of the if then else # so we are back at left margin #!/usr/bin/perl -w <- good use strict; <- good my $dir = "c:/Xwords/"; my $n=length "c:/Xwords/"; # confusing why use $n why not $length # also why not length $dir # that is what you want afterall # why type you dir twice: laziness and typos my $from = '.puz'; my $to = 'A.puz'; my $newdir = "c:/Xwords/PrintedXwords/"; while (<$dir*$from>) { my ($old,$new,$full); $old = $full = $_; # see how I coded this $new = $old = substr $_,$n; # it is the same but cleaner $new =~ s/$from$/$to/; # you have not coded anything so why the two blank lines print " \n \n"; # if you put in a leading space you get... # if you and blank lines do this print "\n\n.... print " full name of original file is $full \n"; print " name of original file is $old \n"; # you don't need the . to concatenate in a string # you just need "$newdir$new". also { are literals print " full name of new file is {$newdir.$new} \n"; # if you want 3 blank lines go \n\n\n" print " \n \n"; # this need to be written as I did with no curlies # curlies are block delilimiters # you should check if this suceeds or fails as demonstrated # above with the or die "message $!" the message lets you # say why you have died and $! if the Oh f@#$ varibale # where perl puts the error message. The die alone just # gives a line number rename $full, {$newdir.$new}; } # I have added a counter that will register if all goes to plan # this will always give you a cheery message regardless! print "Files renamed !";