in reply to Write to multiple files according to multiple regex

You are not resetting the value of $i inside the while loop. It will therefore go on incrementing unchecked and extend far beyond the ends of your arrays. Move the initialisation of $i inside the loop to avoid this. Update: forget this - I missed the re-zero at the end :-/

And try testing with a smaller data file for starters.