in reply to Iteration condition...

I may be misunderstanding the post by here is my opinion. If you are trying to parse HTML. Use one of the many modules to do it for you. Such as HTML::TreeBuilder. Or if you are working with XML: XML::Simple. Modules such as these have the ability to parse markup language into a convenient data structure. Just my 2 cents.