FIRSTKEY this This method will be triggered when the user is going to iterate through the hash, such as via a keys() or each() call. sub FIRSTKEY { carp &whowasi if $DEBUG; my $self = shift; my $a = keys %{$self->{LIST}};# reset each() iterator each %{$self->{LIST}} } NEXTKEY this, lastkey This method gets triggered during a keys() or each() iteration. It has a second argument which is the last key that had been accessed. This is useful if you're carrying about ordering or calling the iterator from more than one sequence, or not really storing things in a hash anywhere. For our example, we're using a real hash so we'll do just the simple thing, but we'll have to go through the LIST field indirectly. sub NEXTKEY { carp &whowasi if $DEBUG; my $self = shift; return each %{ $self->{LIST} } } #### package Foo; sub TIEHASH { bless {}, shift; }; sub FIRSTKEY { wantarray ? print "Array\n" : print "Scalar\n" }; *NEXTKEY = *FIRSTKEY; sub FETCH { return }; package main; tie %me, Foo; () = each %me; scalar each %me; __END__ Scalar Scalar