#!/usr/bin/perl $count = 1; foreach (glob "*.jpg") { if ($_ !~ /\Q.jpg/i) { next; } if ($_ =~ /^tn_/i) { next; } $str = sprintf("%02d.jpg",$count++); if ($str eq $_) { next; } rename($_, $str); print "Renamed $_ to $str\n"; } if ($count==1) { print "No .jpgs found or none needed to be renamed.\n"; }