foreach $srcip (keys(%srciphash)) #### foreach $dstip (keys(%{$srciphash{$srcip}})) #### $srciphash{$srcip}{$dstip} = 1; #### my %srciphash = ( foo => { one => undef }, bar => { two => undef }, baz => { three => undef }, ); foreach my $srcip(keys %srciphash) { foreach my $dstip(keys %{ $srciphash{ $srcip } }) { print "$srciphash{$srcip}{$dstip} = 1\n"; } } __output__ $srciphash{foo}{one} = 1 $srciphash{baz}{three} = 1 $srciphash{bar}{two} = 1