#!/usr/bin/perl -w use strict; my $dir = "c:/test/"; my $from = '.pl'; my $to = 'A.pl'; my $newdir = "c:/test/test/"; # make the target dir if it does not exist unless (-d $newdir) { mkdir $newdir or die "Unable to make dir $newdir $!\n"; } my $count = 0; while (<$dir*$from>) { my ($old,$new,$full); $full = $_; $new = $old = substr $full, length $dir; $new =~ s/$from$/$to/; print "Full name of original file is $full \n"; print "Name of original file is $old \n"; print "Full name of new file is $newdir$new \n"; $count++ if rename $full, $newdir.$new or die "Error renaming $!\n"; } print "$count Files renamed!" if $count; # everything after the __END__ token is ignored by Perl __END__ # here is script with comments