>perl -wMstrict -le "my $ar = [ qw(X1 Mt10 mT2 y20 Y1 Y10 mt20 x20 X10) ]; ;; my @sorted = map { undecorate($_) } sort map { print qq{'$_'}; $_ } map { decorate($_) } @$ar ; ;; print qq{'$_'} for @sorted; ;; use constant WIDTH => 10; use constant SEP => ':'; ;; sub decorate { my ($num) = $_[0] =~ m{ (\d+) }xms; my ($alpha) = $_[0] =~ m{ ([[:alpha:]]+) }xms; return sprintf '%0*d%s%s%s', WIDTH, $num, lc($alpha), SEP, $_[0]; } ;; sub undecorate { return substr $_[0], 1 + index $_[0], SEP; } " '0000000001x:X1' '0000000010mt:Mt10' '0000000002mt:mT2' '0000000020y:y20' '0000000001y:Y1' '0000000010y:Y10' '0000000020mt:mt20' '0000000020x:x20' '0000000010x:X10' 'X1' 'Y1' 'mT2' 'Mt10' 'X10' 'Y10' 'mt20' 'x20' 'y20'