use List::MoreUtils qw( natatime ); my $next_two = natatime 2, @x; while ( my ( $x, $y ) = $next_two->() ) { # do something with $x & y };