#!/usr/bin/perl use strict; use warnings; use Data::Dumper; ... my @all_profile; my %homes_by_names; foreach my $row ( @{ $sql } ) { my %profile; $profile{ NAME } = $row->{'name'}; $profile{ ADDRESS } = $row->{'address'}; $profile{ HOME } = $row->{'home'}; # I will need to count the how many homes here push ( @{ $homes_by_names{$profile{ HOME } } }, \%profile); push @all_profile, { 'HOME COUNT' => scalar @{ $homes_by_names{HOME} }; push @all_profile, \%profile; } print Dumper \@all_profile; $VAR1 = [ { 'NAME' => 'John Doe', 'ADDRESS' => 'Main Street', 'HOME' => 'House 1', 'HOME COUNT' => '3', }, ... =data # Sample data to show how I need to count how many Houses per person John Doe, Main Street, House 1 John Doe, Main Street, House 1 John Doe, Main Street, House 1 Mary Lou, Central Street, House 1 Mary Lou, Central Street, House 1 Mary Lou, Central Street, House 1 Mary Lou, Central Street, House 1 Jane B,. Squere Rd., House 1 Maria D., Pat street, House B Maria D., Pat street, House B