## tested my @out = map { substr $_, 6 } ## hardcoded "6" here... sort map { my $val = (split /\|/)[4]; sprintf "%06d$_",$val } ## ... and here ;