my @sorted_array = sort { # compare the second numbers substr($a, 12, 9) <=> substr($b, 12, 9) # compare the third numbers or substr($a, 22, 12) <=> substr($b, 22, 12) } @array;