use strict; use warnings; my @Records; open(FILE,"file.txt"); while (){ @Records = ; } @Records = sort {$a cmp $b} @Records; # and now to test. my $i = 0; while ($i <= $#Records){ print "$Records[$i]\n"; $i++; }