in reply to Sort Problem

If I understand your question, you want the lines contained in @DB to be printed in sorted order. You didn't say which field the sorting should be based on, but I'll assume you want it based on the initial field. Your examples only show 4-digit numbers in the first field, but I'll assume that you could have 3-digit and/or 5-digit numbers as well, and you want the sort to be numeric. I think the part of the foreach loop that you are not showing is the part where you want to print the lines in sorted order. The answer to your question is that you need to apply the sort before going into the loop -- this could do it (if all my assumptions are correct):
foreach $rec ( sort { $a <=> $b } @DB ) { chomp $rec; ($num,$name,$email,$xnumber) = split /\#/, $rec; # print and do whatever else you want... }
The sort block uses numeric comparison; it will do the right thing with the strings in your example, no matter how many digits are in the first field. If you want to sort based on some other field in each line, you'll need to build a hash with the hash key being the field you are sorting on, and the value being the other fields in each line. That means you need one loop over @DB to split each line and store it in the hash; then you need a second loop to print out the data in sorted order, and this second loop begins with something like:
foreach my $key (sort keys %dbhash) { # print the data found in $dbhash{$key} }