Since the first expression glob("$_/f*") is only true for 'dir1', it should only return that element of the directory list (even though glob returns 3 files in that directory).
You are missing the fact that grep puts the glob in a scalar context, and that makes it act as an iterator:
In scalar context, glob iterates through such filename expansions, returning undef when the list is exhausted.
In reply to Re^3: Using grep and glob to find directories containing file
by BrowserUk
in thread Using grep and glob to find directories containing file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |