in reply to Re^2: Assigning scalars to scalar template includes
in thread Assigning scalars to scalar template includes

What I am trying to do is: ...

O.K., but what do you want to do with $main_template if there are no results? Leave %%searchresults%% there? Or do you want to erase it? I assume you want to erase it.

Here's enough of a start that you should be able to figure the rest out yourself:

# join results into a single variable; this may be empty my $results = join('', @results); # do the substitution. $main_template =~ s/%%searchresults%%/$results/g;