in reply to parsing html

McA's solution will fix your immediate question, but if you are parsing HTML in anything other than an educational or 1-off context, I would suggest you use a CPAN module rather than reinvent the wheel; perhaps HTML::Parser or Mojo::DOM would be helpful. HTML in the wild is notoriously hard to handle in a general way.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.