my $fetch = sub { my ($fh) = @_; return if eof $fh; return \(scalar <$fh>); }; ... while (my $ref = $next->()) { print "$$ref\n"; }