#!/usr/bin/perl use strict; use warnings; use HTML::Template; use Data::Dumper; $Data::Dumper::Indent = 1; my %h = get_hash(); my @outer; for my $rep (keys %h){ my @inner; for my $detail (@{$h{$rep}}){ push @inner, $detail; } push @outer, { rep => $rep, inner => [@inner], } } my $param = {outer => [@outer]}; print Dumper $param; exit; # the following not directly relevant my $t = HTML::Template->new(filename => 'kwaping.html') or die "can't parse template: $!"; $t->param($param); print $t->output; sub get_hash{ return ( 'One' => [ { 'apptype' => 'xxx', 'count' => '123', 'companyid' => 'xxx', 'state' => 'xx' }, { 'apptype' => 'xxx', 'count' => '123', 'companyid' => 'xxx', 'state' => 'xx' }, { 'apptype' => 'xxx', 'count' => '123', 'companyid' => 'xxx', 'state' => 'xx' } ], 'Two' => [ { 'apptype' => 'xxx', 'count' => '123', 'companyid' => 'xxx', 'state' => 'xx' }, ] ); }