in reply to Loop skipping

I also tried hard to follow the code, and also got a headache. I'll second husker's comment, please give us a running program, i.e., the @pathway_name array, a short "@file" array, and indicate what you expact and what you are getting.

Another suggestion: please use "use strict", it will catch many errors.