http://qs321.pair.com?node_id=939690


in reply to How to improve my code? main concern:array as hash element

You probably need
my %gp = ( ... Gi => \@gi, # an array ref Gt => \@gt, );
Hash values can only be scalars. An array reference is a scalar so we can use that.

In your while loop you will first need to test if it is an array ref and, if so, dereference it. Something like

... $j = $gp{$i}; my @values; if (ref $j eq 'ARRAY'){ @values = @{$gp{$i}}; } else { @values = ($j); } for $val (@values){ ...
(not tested)
update: fixed typo