use strict; use warnings; use Data::Dumper; my %hash; my $count = 0; # populating a deeply nested hash for my $ip (qw ) { for my $port ( qw ) { for my $status (qw ) { for my $user (qw ) { $hash{$ip}{$port}{$status}{$user} = $count++; # (just a dummy value for testing) } } } } # print Dumper \%hash; # iterating through the nested hash for my $nest0 (values %hash) { while (my ($port, $nest1) = each %$nest0) { while (my ($status, $nest2) = each %$nest1) { for my $freq (values %$nest2) { print "$port\t$status\t$freq\n"; } } } }