For my use case I don't know in advance which items to set in the header and which in the page, so this solution doesn't really scale past the small example. (Much like moving the title as suggested by ww initially failed to solve the general problem).

HTML::Template puts together html very nicely. Everything else should be done by your script. I think you are trying to get the template to do too much.

Your "content will be coming from... a database" so you could add a field which specifies "which items to set in the header and which in the page" or alternatively put that information in your script/config file i.e. one way or another, make a table.