http://www.perlmonks.org?node_id=917505


in reply to File::Glob infinite loop with while loop unlike core glob function

No, I don't think it is a bug. glob returns a list. In scalar content, as while establishes, you just get the last element of the list. In this case, it is a non-empty string, so it acts as true, and it never changes, so there is an infinite loop. If you do
@files = glob "$folder/*.txt";
the list, in array context, turns into a real array, over which you can iterate with your favorite iterator.