#! /usr/bin/perl use warnings; use strict; use HTML::Template; use Data::Dumper; my $text = "bar=\n"; my $template = HTML::Template->new(scalarref => \$text, loop_context_vars => 1); $template->param(foo => [{bar => 10}, {bar => 20}]); my $array_ref = $template->param('foo'); if ($array_ref) { print Dumper($array_ref); print Dumper($array_ref->[1]); # # add a new element # push (@$array_ref, {bar => 30}); $template->param(foo => $array_ref); } print $template->output;