#!/usr/local/bin/perl -w use strict; my @database = ; my @sorted=sort{my $one=substr($a,rindex($a,'|')); my $two=substr($b,rindex($b,'|')); ($one <=> $two) } @database; print @sorted; __DATA__ a|b|c|10 d|e|f|100 g|h|i|2 #### Argument "|10\n" isn't numeric in ncmp at tmp.pl line 9, chunk 3. Argument "|100\n" isn't numeric in ncmp at tmp.pl line 9, chunk 3. Argument "|100\n" isn't numeric in ncmp at tmp.pl line 9, chunk 3. Argument "|2\n" isn't numeric in ncmp at tmp.pl line 9, chunk 3. a|b|c|10 d|e|f|100 g|h|i|2 #### my @sorted = map $_->[1], sort { $a->[0] <=> $b->[0] } map [ substr($_,rindex($_,'|')+1), $_ ], @database; #### my $width = 10; # must be at least as big as the longest field being compared my @sorted = map substr($_, index($_, '|')+1), sort map sprintf("%0${width}d|%s", substr($_,rindex($_,'|')+1), $_), @database;