Completely untested, so take it with a grain of salt.
my $pessoais = "produtos/pessoais.dat";
my $mailprog = "/usr/sbin/sendmail";
my $search_for = "a";
my $search_field = "all";
my @results = ()
search_database($pessoais, $search_for);
my $count = @results; # I'll assume that @results is a global
foreach my $result (@results) {
my ($key, $description, $speed, $ref, $qid) = split(/\|/, $result)
+;
# the print MAIL confuses me as I can't see where it
# was opened or where %FORM is from (params?), so
# I'll leave that as an exercise for the reader.
}