in reply to Can I check if a loop's scope is entered for the first time?

You might also find it useful to take a look at how Var::Pairs implements its each_kv() and each_pair() iterators.
That technique could easily be generalized to any handle kind of user-defined iterator, not just the standard hash and array iterators.