sub list_iter { my @list = @_; return sub { return @list ? shift(@list) : (); }; } my $iter = list_iter('a', 1, '', 0, undef, -1); while( my ($next) = $iter->() ) { print( $next // '[undef]', "\n" ); } #### sub list_iter { my @list = @_; return sub { return 0 if !@list; $_[0] = shift(@list); return 1; }; } my $iter = list_iter('a', 1, '', 0, undef, -1); while( $iter->( my $next ) ) { print( $next // '[undef]', "\n" ); } #### a 1 0 [undef] -1