for (@somelist) { my($foo,$bar) = split; my $x = somecalc($foo,$bar); $somehash{ $foo }->{ $bar } ||= []; push @{ $somehash{ $foo }->{ $bar } }, $x; }