my @a = qw( a b c d ); my $i = sub { @a ? splice(@a, 0, 2) : () }; while (my ($x,$y) = $i->()) { print("$x:$y\n"); }