... my $key = ; chomp($key); my $val = ; chomp($val); if (exists $hash{$key}) { $hash{$key} = [ $hash{$key} ] unless ref($hash{$key}); push @{$hash{$key}}, $val; } else { $hash{$key} = $val; } #### $VAR1 = { 'bar' => 'val3', 'baz' => 'val4', 'foo' => [ 'val1', 'val2' ] }; #### ... my $key = ; chomp($key); my $val = ; chomp($val); push @{$hash{$key}}, $val; #### $VAR1 = { 'bar' => [ 'val3' ], 'baz' => [ 'val4' ], 'foo' => [ 'val1', 'val2' ] };