in reply to Stupid loops, or is it just me?

As antirice has said, you need semicolons in your for loops. That should fix the problem. To prevent it in the future, consider writing your loops using a foreach style. For example, rewrite for ($i=0; $i<147; $i++){ ... } as:

for my $i ( 0 .. 146 ) { # . . . }
Not only is the syntax simpler making it easier to type and read, you will be less prone to making off-by-one errors too.

Update: Yes, I meant "semicolons" not "commas"... thanks rob_au.

-sauoq
"My two cents aren't worth a dime.";