use strict; use warnings; my $array = [ { 'name' => 'Discount', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Documents', 'reference' => '100 ', 'type' => 'Paper' }, { 'name' => 'Money', 'reference' => '340 ', 'type' => 'Plastic' }, { 'name' => 'State', 'reference' => '40 ', 'type' => 'Cotton' }, { 'name' => 'Slice', 'reference' => '30 ', 'type' => 'Cotton' }, { 'name' => 'Part', 'reference' => '45 ', 'type' => 'Cotton' }, ]; my %hash; #$hash{$_->{'type'}} {$_->{'name'}} = $_->{'reference'} for @$array; $hash{$_->{'type'}}{ $_->{'name'} }for @$array; print "Results:\n"; for my $k1 (sort keys %hash) { print " $k1:\n"; for my $k2 (sort keys %{$hash{$k1}}) { print " $k2 - $hash{$k1}{$k2}\n"; } } #### Output: Results: Cotton: Part Slice State Paper: Discount Documents Plastic: Money