use warnings; use strict; use Test::More; my @AoH = ( {'targetL' => 'foisonnement', 'origin' => 'AMG', 'count' => '1'}, {'targetL' => 'foisonnement', 'origin' => 'IDBR', 'count' => '1'}, {'targetL' => 'gonfler', 'origin' => 'IWWF', 'count' => '1'}, {'targetL' => 'due', 'origin' => 'IWWF', 'count' => '1' }, {'targetL' => 'due', 'origin' => 'IWWF', 'count' => '1' }, ); my @AoHfinal; my %targets; for my $h (@AoH) { push @AoHfinal, ($targets{$$h{targetL}}={targetL=>$$h{targetL}}) unless $targets{$$h{targetL}}; $targets{$$h{targetL}}{origin}{$$h{origin}}++; $targets{$$h{targetL}}{count}++; } $$_{origin} = join ' ', sort keys %{$$_{origin}} for values %targets; is_deeply \@AoHfinal, [ {'targetL' => 'foisonnement','origin' => 'AMG IDBR','count'=>'2'}, {'targetL' => 'gonfler','origin' => 'IWWF','count' => '1'}, {'targetL' => 'due','origin' => 'IWWF','count' => '2'}, ] or diag explain \@AoHfinal; done_testing;