What exactly is section(arg)
in your arrayref ? Is this a TT macro or is your example pseudo-code?
I appreciate you don't want to rewrite the whole thing. Is it possible to stash the section headers in a fashion that permits later identification that this is what they are, i.e.:
content_list=[
{ section => 'First Section' }, "somecontent", "some_other_content",
{ section => 'Second Section' }, "somecontent", "some_other_content"
];
and later on:
[% IF entry.section %]
<tr>
<th> [% entry.section %]</th>
</tr>
[% END %]
If you go down this path, you might want to consider turning all the elements in the array to little hashrefs, i.e.:
content_list = [
{ content => 'First Section', section=>1 }, { content => "somecontent" },
{ content => "some_other_content" }, { content => 'Second Section', section=>1 },
{ content => "somecontent" }, { content => "some_other_content", some_flag=>1 }
];
Then each entry IN content_list
can be an object with its own properties to suit.
Another approach would be to create a little hash of the content items you know are headers, and test for them, i.e.:
[% SET header = { 'First Section' => 1, 'Second Section' => 1, ... }; %]
and later on:
[% IF header.$entry %]
<tr>
<th>[% entry %]</th>
</tr>
etc.