If upto() indeed returned an iterator that you could then call, all would be well, but that doesn't seem to have happened. If it did then your original code would look somewhat like this:
my $iter = upto(5);
while (my $item = $iter->()) {
print "Item: $item\n";
}
With this the intent would be clear. And you would be able to specify exactly what do you want. I'm not talking about the implementation of upto(), I'm talking about its use! In the example I gave you, with the two nested loops, are the two upto(5) things the same iterator or two separate ones? If they are separate then how come you apparently assume the get_commands() to be a single iterator? And if it's the same iterator, how do I create a separate one?
Imagine you wanted to make the get_commands() more general and allow you to read the commands from a file specified by the filename. Now am I supposed to pass the same filename to all occurences of the get_commands()? Or just the first and all following will use that file? How will I know they are not trying to access the <>? And how do I open two iterators at once?