for (<*>) { if(/\.TMB/i) { $old=$_; s/\.TMB$/T\.JPG/; die "$_ already exists" if (-e $_); rename($old, $_) or die "Failed to rename\n"; } }