use Data::Dump 'pp'; # a nicer Data::Dumper my @keys = qw {red blue red}; my @vals = (1, 2, 3); my %hash; push @{$hash{$_}}, shift @vals for @keys; pp \%hash; __END__ { blue => [2], red => [1, 3] }