The flip-flop operator becomes true when the left-hand expression is true, and stays true until the right-hand expression is true. However, we can take advantage of the fact that Perl doesn't require us to use "\n" to end a "line" -- we can tell Perl that a record (the proper word to use, rather than line) ends in the string "<!--startdata-->\n". If we do that, we read one record in, and the redefine a record to end in "<!--enddata-->\n" -- when we read the next record, and that's all the information you need:

chomp() does not remove a trailing "\n" character -- it removes the value of $/ from the end of a string. And this variable defaults to "\n". But since I changed it to "<!--enddata-->\n", chomp() removes THAT from the end of the string.