use strict; use warnings; my $prefix; my $midCount; my $lastSuffix; while () { chomp; my $oldName = $_; $prefix = substr $_, 0, 3 if ! defined $prefix; my $suffix = substr $_, -2; ++$midCount if ! defined ($lastSuffix) or $suffix <= $lastSuffix; $lastSuffix = $suffix; my $newName = sprintf ("%03s%06d%02d", $prefix, $midCount, $suffix); print "$oldName -> $newName\n" }