#### Old sort (that doesnt work properly ) with first 10 records extracted foreach my $k (keys %IND) { @indsort=(sort { $a <=> $b } @{$tmp}); foreach $line(@indsort[0..9]){ print "$line\n"; } } #### #### New sort (which works!) with first 10 records NOT extracted foreach my $tmp (keys %IND) { my @lines; open(FILE, "+< tmp/$tmp.dat") or die "file:$tmp $!"; while () { chomp; my @line = split(','); push(@lines, \@line); } @lines = sort { $a->[0] <=> $b->[0]} @lines; foreach my $line (@lines) { print join(",", @{$line}) . "\n"; } } #### print join(",", @{$line}) . "\n";