As was suggested before, you have tools available to make sure your script is syntactically correct first before worring about whether the logic is correct.
Code:
C:\Temp>perl -c t.pl
Number found where operator expected at t.pl line 317, near "150060 1"
(Missing operator before 1?)
syntax error at t.pl line 317, near "150060 1"
Missing right curly or square bracket at t.pl line 608, at end of line
syntax error at t.pl line 608, at EOF
t.pl had compilation errors.
There are 104 { characters, and 103 } characters. You can use the Notepad++ count feature to see this easily. I'll leave you to figure out where you have a mismatch.