use strict; use warnings; use Getopt::Std; my %opt; getopts('e:',\%opt) or die; die unless exists $opt{e}; opendir(HERE,'.') or die "Epic failure.\n"; my @paths = readdir(HERE); closedir(HERE) or warn "Whatever.\n"; open(DATA,"data.txt") or die "Rename your text file 'data.txt'.\n"; my @data; while() { chomp; next unless length; push(@data,$_); } close(DATA) or warn "Whatever two.\n"; foreach my $path (@paths) { next unless $path =~ /.*\.$opt{e}$/i; my $newpath = sprintf('%s.%s',shift @data,$opt{e}); rename($path,$newpath); }