This reminds me somewhat of Petal,
Actually not really, what the OP wants is much closer to my own HTML::Seamstress
. Petal embeds a mini-language within HTML... Seamstress is pure Perl and pure HTML and nothing else.
Seamstress takes its inspiration from XMLC and I am very grateful to lachoy for mentioning it. Petal takes its inspiration from TAL.
To understand the difference between push-style templating (Seamstress) and pull-style templating (tt/mason/petal/html::template, etc) you should read
Terence Parr's paper on the subject.