Well the first thing you need to do when it comes to parsing data records from HTML documents, is to look at the markup structure of the document and determine the simplest "search rule" that matches all data records (without matching any false positives).
If I understand your post correctly, each record in your case will be of the form <div class="message1">...</div>. But that's not enough information to determine the "search rule" for matching all of them, you need to look at what exactly changes from record to record, and at the page structure they're embedded in.
Here are some examples of what the "search rule" could be, depending on the exact document structure at hand (sorted from simpler to more complex):
- "All <div> elements anywhere in the document"
- "All <div> elements that are direct children of <body>"
- "All <div> elements that are direct children of a container element that has a unique id"
- "All <div> elements that have the attribute class="message1""
- "All <div> elements that have the attribute class="messageX", with X being a number"
- "All <div> elements that have a <span class="id"> child element"
- ...
Once you have determined the simplest rule for matching records (and no false positives!) for your particular use-case, you can then start thinking about how to implement the parsing. Report back once you are at that stage and need more help with that.
PS: As for formatting questions on PerlMonks, it's best to put code (including HTML markup) in <code>...</code> tags - among other benefits you can then keep the angled brackets in the code, they will show up verbatim.