$ perl -e ' > my %h=(qw(a b c d e f)); > { my @each = %h; > while (my $k = shift @each) { > my $v = shift @each; > print "$k => $v\n"; > }}' c => d e => f a => b #### package OOEach; sub new { my ($class) = @_; return bless {}, $class; } sub each { my $self = shift; $self->{queue} ||= [@_]; # note: will only init once my $k = shift @{$self->{queue}}; my $v = shift @{$self->{queue}}; return ($k, $v); } ;