#! perl -slw use strict; my @inventory = ( [ qw'2003 abc rel 999' ], [ qw'1999 hds sdf 100' ], [qw'2010 kls pol 1400' ], );; while( my @order = split ' ', ) { print "@$_" for sort{ my $r; for(@order) { if( $a->[ $_ ] =~ m[^\d+$] && $b->[ $_ ] =~ m[^\d+$] ) { ( $r = $a->[ $_ ] <=> $b->[ $_ ] ) and last; } else { ( $r = $a->[ $_ ] cmp $b->[ $_ ] ) and last; } } $r } @inventory; } __END__ c:\test>junk42 0 1999 hds sdf 100 2003 abc rel 999 2010 kls pol 1400 1 2003 abc rel 999 1999 hds sdf 100 2010 kls pol 1400 2 2010 kls pol 1400 2003 abc rel 999 1999 hds sdf 100 3 1999 hds sdf 100 2003 abc rel 999 2010 kls pol 1400 1 2 2003 abc rel 999 1999 hds sdf 100 2010 kls pol 1400 ^Z