# validate our keywords.
unless ( defined $fields{keywords} &&
fields{keywords} ne '' )
{
# complain, bail out of this run.
}
my @keywords = split ' ', $fields{keywords};
# find actual matches in highest- to lowest-score order
my @normal_hits = reverse sort find_hits "normal_list.txt", @keywords;
my @premium_hits = reverse sort find_hits "premium_list.txt", @keywords;
# keep lists reasonable
if ( @normal_hits > 100 ) { splice @normal_hits, 100 }
if ( @premium_hits > 100 ) { splice @premium_hits, 100 }
# now join them together for presentation:
my $normal_hits = join '
', @normal_hits;
my $premium_hits = join '
', @premium_hits;
# finally, do the now-obvious substitution:
$template =~ s/%%normalresults%%/$normal_hits/;
$template =~ s/%%premiumresults%%/$premium_hits/;