Ok, this is a completely unordered list, but I'll point out what I notice first pass:
- You don't use strict, and you aren't localizing your variables with my or local
- You initialize your scalar variables with empty sets. While this isn't really an error, it's not needed. When creating a variable, it is quite all right to simply declare its existance, perl initializes it to a default empty value.
- You clear your variables the same way you're initializing them. If you truly wish to clear them, either set them to '', 0 or use undef. Not to say that your method is by definition wrong, just that it isn't commonly done.
- In cases with nested loops and the loop control operators, it's usually best to name your loops just in case.
- Around line 33 you use a chomp statement, but I suspect something got cut out, because you completely loose me there.
Nothing horrible, and easily fixed.
On a related note, I, personally, couldn't get your code to run, but I suspect that's just because of the way you entered it into the text box.
Edit: Minor correction, expanded on a statement.
My code doesn't have bugs, it just develops random features.