my @array=(); for my $word (keys %{$has{$w1}->{$w2}}) { push @array, ($word) x $hash{$w1}->{$w2}->{$word}; }