$|=1; # So it works in the Open Perl IDE

chdir "d:/temp" or die "Couldn't change dir: $!"; # goto the dir with the files
@files = glob "*.txt"; # get the names of the text files

foreach $e (@files){ # do this for all files in the folder
  $new = $e; # create variable for the new name of the file
  $new =~ s/\.txt$/.bak/; # replace the .txt at the end with .bak
  rename "$e","$new" or warn "Renaming of $e failed: $!"; # rename the file or warn
}

