in reply to Need to sort large table of data...

The solutions provided by igelkott both produce the same output for the example input data:
2 - 1 1 1 1 1 1 - 1 1 1 2 8 1 - 1 5 6 12 12

However, this output does not conform to the example output given by the OP:
2 - 1 1 1 1 1 1 - 1 2 1 1 8 1 - 1 6 5 12 12

The following code produces output that seems to conform to the OP's exemplified requirement (the two added values of '0 0 0 0 0' test for proper handling of leading-zero removal):

2 - 0 0 0 0 0 2 - 1 1 1 1 1 1 - 1 2 1 1 8 1 - 1 6 5 12 12

Code:

use warnings; use strict; my @AllPatterns = ( '1 2 1 1 8', '0 0 0 0 0', '1 6 5 12 12', '0 0 0 0 0', '1 1 1 1 1', '1 1 1 1 1', ); { # limit scope of array processing variables my $biggest = 10; # biggest number (most decimal digits) my $fmt = join ' ', ("%0${biggest}ld") x 5; my $lead0s = qr{ \b 0{1,@{[ $biggest - 1 ]}} }xms; my %seen; # unique-ifing hash @AllPatterns = # 7. save to original array map { "$seen{$_} - $_" } # 6. make into final format grep { not $seen{$_}++ } # 5. only patterns not seen yet map { s{$lead0s}{}xmsg; $_ } # 4. remove padding sort # 3. lexicographic ascending sort # map { print "'$_' \n"; $_ } # 2b. FOR DEBUG map { sprintf $fmt, split } # 2. pad fields to constant widths @AllPatterns # 1. for all patterns... ; } # end scope of array processing variables print join("\n", @AllPatterns), "\n";