# functional my @strings; while (defined (my $next = next_term())) { last if length($next) > 4; push @strings, $next; } # tied scalar use Tie::ScalarIter; tie my($iter), 'Tie::ScalarIter', 'aa', 'a'; my @strings; while (defined (my $next = $iter)) { last if length($next) > 4; push @strings, $next; }