Hi,
just had a quick look over it.
Is there a reason why you sometimes use <> and sometimes <STDIN> to read in? You should know that <> is not exactly the same as <STDIN> because it will also try to read from filenames given in @ARGV, but I'm not sure what order right now. Anyway a s/<>/<STDIN>/ might make your code more consistent, and reduce the chance for buggy behavior if someone calls your script with arguments.