A basic challenge of iterators
Let's try
sub mymap(@list, &block) { my @result; while @list { push @result, &block(@list.shift); } @result; } mymap($file.lines, &block);
Now the lines in @list are discarded as they are processed.
But what about ... ?