foreach my $results(@$hash_of_excel){ my $specificresults = GroupResults($results); } sub GroupResults{ my( $AllRecords )= @_; my $specificResults = {}; foreach my $colname(keys %$AllRecords){ for my $group ('User','Residence','IDs','Profile'){ $specificResults->{$group}->{$colname} = $AllRecords->{$colname}; } } warn Dumper($specificResults); return $specificResults; }