use warnings; use strict; my %fruit = ( apple => ['red','green'], kiwi => 'green', banana => 'yellow', ); my %colors; for my $f (keys %fruit) { for my $c ( ref $fruit{$f} ? @{ $fruit{$f} } : $fruit{$f} ) { push @{ $colors{$c} }, $f; } } use Data::Dump; dd \%colors;