#! perl -slw use strict; use Time::HiRes qw[ time ]; my @a; $#a = 1e6; my $n = 0; $a[ $n++ ] = $_ while <>; printf "%d records; check memory", scalar @a; ; my $start = time; my @sorted = @a[ map { unpack 'N', substr($_,-4) } sort map { pack 'NNN', $a[ $_ ] =~ m[(\d+) (\d+)], $_ } 0..$#a ]; printf "Took %.6f seconds; check memory? ", time()- $start; ;