#!perl -w use strict; opendir(DIR,".") or die "Couldn't opendir on .: $!"; while($file = readdir(DIR)){ my $oldfile = $file; $file =~ s/\s+/_/g; push @{$hash{$file}}, $oldfile; } closedir(DIR) or warn "Couldn't close directory .: $!"; foreach my $key (keys %hash){ if(scalar(@{$hash{$key}}) != 1){ print "The following files would have been renamed to the same thing:\n" local $"="\n"; print "@{$hash{$key}}", "\n"; } else{ print "$hash{$key}[0] -> $key " my $status = rename $hash{$key}[0], $key; if(!$status){ print "Failed\n"; } else{ print "Succeeded\n"; } } }