liverpole has answered your question, but there are a few tips that may help you in general.
Use strictures. Add use strict; use warnings; at the top of every script you write. They will save you time.
Convince your editor to use spaces for indentation rather than tabs. Your code looks a mess because the tabs have evaporated.
Avoid putting multiple statements on a line. Unless you are writing on a PDA, screen lines are not generally an issue and putting stuff where it can be seen makes a big difference to understanding - especially when other people may have to work with you code.