#!/usr/bin/perl use warnings; use strict; opendir my $dir, '.' or die "opendir .: $!\n"; my $file; my $count = 0; while (defined($file = readdir($dir))) { # give yourself some progression feedback $count++; print "file $count ...\n" unless $count % 1000; # skip all files not begining with b next unless $file =~ /^b/; # if you've created directories, may need to skip them; # this will slow things down, so don't do so unless necessary next unless -f $file; # do something with the file rename $file, "b/$file" or die "rename $file b/$file: $!\n"; }