in reply to Multiple HTML field names

First of all you really should use an existing templating system. Lots exist, and they've already solved lots of problems that you're going to run into.

That said, you can tackle this one by doing one substitution that puts in both:

$main_template =~ s/%%keywords%%/$fields{'keywords'} $fields2{'search' +}/g;