use strict; use HTML::Template; use Data::Dumper; # just a simple way to try both test cases my $page = (shift) ? 'home' : 'articles'; my $html = do { local $/; }; my $template = HTML::Template->new(scalarref => \$html); my $articles = [ { title => q|Title 1|, body => q|blah blah blah, blah blah blah blah|, }, { title => q|Title 2|, body => q|blah blah blah, blah blah blah blah|, }, { title => q|Title 3|, body => q|blah blah blah, blah blah blah blah|, }, { title => q|Title 4|, body => q|blah blah blah, blah blah blah blah|, }, ]; $template->param( class => $page, articles => ('home' eq $page) ? [(@$articles)[0..1]] : $articles, ); print $template->output(); __DATA__