#!/usr/bin/perl -w use strict; my @TestData = ( 'a', 'NTX', 'NT8', 'NT9', 'NT10', 'NT11', ); { foreach my $inputData (@TestData) { my $outputData = $inputData; while (length($outputData) < 4) { if ($outputData =~ /^(\D*)(\d+)$/) { my $systemType = $1; my $systemNumber = $2; my $totalLength = length($systemType) + length("$systemNumber"); while ($totalLength < 4) { $systemNumber = "0$systemNumber"; $totalLength = length($systemType) + length("$systemNumber"); } $outputData = "$systemType$systemNumber"; } else { $outputData .= '_'; } } printf "%-4s -> %s\n", $inputData, $outputData; } } exit; __END__