On top of what's already mentioned, also note that each iteration of your loop, you process
three lines:
- The guard of the while reads a line, puts it in $_. This line is processed (by chomp and split).
- A line is assigned to $nextline. Which is then unused.
- Inside events, another line is read, assigned to another $nextline. This one remains unused as well.