use strict; use warnings; my @values = map {chomp; /(\S+)/g} ; my @sorted = map {tr/\0//d; $_} sort map {normalize ($_)} @values; (my $str = "@sorted") =~ s/(.{5,70})\s/$1\n/g; print $str; sub normalize { my $str = shift; my @parts = map {/\D/ ? $_ : ("\0" x (10 - length $_)) . $_} split /(?<=\d)(?=\D)|(?<=\D)(?=\d)/, $str; return join '', @parts; } __DATA__ a10_10[10] b10_10[10] b2_1[1] b2_1[2] b2_1[10] b2_2[1] b2_2[2] b2_2[10] b2_10[1] b2_10[2] b2_10[10] a1_1[1] a1_1[2] a1_1[10] a1_2[1] a1_2[2] a1_2[10] a1_10[1] a1_10[2] a1_10[10] a10_1[1] a10_1[2] a10_1[10] a10_2[1] a10_2[2] a10_2[10] a10_10[1] a10_10[2] b1_1[1] b1_1[2] b1_1[10] b1_2[1] b1_2[2] b1_2[10] b1_10[1] b1_10[2] b1_10[10] b10_1[1] b10_1[2] b10_1[10] b10_2[1] b10_2[2] b10_2[10] b10_10[1] b10_10[2] a2_1[1] a2_1[2] a2_1[10] a2_2[1] a2_2[2] a2_2[10] a2_10[1] a2_10[2] a2_10[10]