foreach $rec ( sort { $a <=> $b } @DB ) { chomp $rec; ($num,$name,$email,$xnumber) = split /\#/, $rec; # print and do whatever else you want... }