The first code fragment (which I think belongs to your second
alternative) should be faster. Not only because you do less
in the inner loop, but you allow far more filesystem caching
*and* perl doesn't need to compile a new regex at each inner
iteration.
Abigail