my $all_cases = [ #an AoH from a DBI query { 'examiner' => 'Brad', 'case' => '2345432', 'location' => 'Sandwich' }, { 'examiner' => 'Brad', 'case' => '7678979', 'location' => 'Wheaton' }, { 'examiner' => 'Mary', 'case' => '1234534', 'location' => 'Geneva' }, { 'examiner' => 'Mary', 'case' => '8966789', 'location' => 'Aurora' }, ]; my $case_list; my $temp = ""; my $cctr = -1; for my $i ( 0 .. $#$all_cases ) { if ( $all_cases->[$i]{'examiner'} ne $temp ) { $cctr++; $temp = $all_cases->[$i]{'examiner'}; $case_list->[$cctr]{'examiner'} = $temp; } push @{ $case_list->[$cctr]{'casedata'} }, $all_cases->[$i]; } $template->param( case_list => $case_list ); __OUTPUT__ [ { 'examiner' => 'Brad', 'casedata' => [ {'case' => '2345432', 'examiner' => 'Brad', 'location' => 'Sandwich'}, {'case' => '7678979', 'examiner' => 'Brad', 'location' => 'Wheaton'} ], } { 'examiner' => 'Mary', 'casedata' => [ {'case' => '1234534', 'examiner' => 'Mary', 'location' => 'Geneva'}, {'case' => '8966789', 'examiner' => 'Mary', 'location' => 'Aurora'} ], } ];