sub next { my $self = $_[0]; our $arg; local *arg = \$_[1]; if (...) { return 0; } else { $arg = ...; return 1; } } while ($i->next($arg)) { ... }