use strict; use warnings; use Test::More tests => 1; use List::Util 'shuffle'; chomp( my @lines = ); my @shuffled = shuffle @lines; my @sorted = sort my_sort @shuffled; is "@sorted", "@lines", 'same order'; sub my_sort { substr( $a, -9, 1 ) cmp substr( $b, -9, 1 ) || substr( $a, -8, 4 ) <=> substr( $b, -8, 4 ) || substr( $a, 0, (length $a) - 8 ) cmp substr( $b, 0, (length $b) - 8 ) } __END__ Barneym0010.111 Fredm0010.111 namem0010.111 namem0900.111 namem1100.111 namep0000.111 namep0800.111 namep9999.111