# method 1 - always use an array: while (my @values = fetchrow_array()){ my $hash = ($values[0] => [ $values[1] ]); push (@{$hash{$values[0]}}, values[2]) } #### # method 2 - switch scalars to arrays dynamically (good for other # cases, not so good for yours, here for completeness only) # rather than a simple push: if (exists $hash{$values[0]}) { if (not ref $hash{$values[0]} or ref $hash{$values[0]} ne 'ARRAY') { $hash{$values[0]} = [ $hash{$values[0]} ]; } push @{$hash{$values[0]}}, $hash{$values[2]};