for my $name ( keys %hash ) { my $count = 0; for my $entry ( ... ) { # loop over entries under first key $count++; print "$name $entry $count\n"; } }