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" } #### __DATA__ 22200010001 22200010101 22200010102 22200010103 22200010201 22200010001 -> 22200000101 22200010101 -> 22200000201 22200010102 -> 22200000202 22200010103 -> 22200000203 22200010201 -> 22200000301