Keeping your original code you could try this:
for my $h (@suggestionsTemp) {
my $targetL = lc $h->{targetL};
push @suggestionsUnsorted, ($targets{$targetL}={targetL=>$targetL}
+)
unless $targets{$targetL};
$targets{$targetL}{origin}{$h->{origin}}++;
$targets{$targetL}{count}++;
}
$_->{origin} = join ', ', sort keys %{$_->{origin}} for values %target
+s;
Note: changed the way hash references are dereferenced to use the arrow operator.
Output:
$VAR1 = [
{
'targetL' => 'ahnenforschung',
'count' => 1,
'origin' => 'IB'
},
{
'count' => 3,
'origin' => 'EU, IB',
'targetL' => 'akzent'
}
];