in reply to check for contiguous row values

I would recommend a slight rethink of the problem. There are two things (as you've explained it) that need to happen:
  1. We need to capture lines that aren't "THIS IS A BREAK" and process them.
  2. We need to know when we've hit a break line.
I would suggest that you change the logic to reflect that. Right now I don't see you ever checking at all for the break line, which is certainly not going to work.

Try it this way (pseudo-code so you can get the practice writing the Perl):

my @captured; While I still have records: Is this a break line? Y - check_for_more_breaks(@captured) @captured = () next item N - save line to @captured Anything left in @captured? check_for_more_breaks(@captured) sub check_for_more_breaks: # Your actual processing here is unclear; I've taken # a guess at it. my @subgroup; my $last_sequence_number; for each line: extract the fields is last_sequence number defined? N - save this one as the last sequence number save the current data of interest in @subgroup next else is there a gap in the sequence numbers? Y - summarize(@subgroup) @subgroup = (); save current sequence number as last save the current data of interest next
For summarize(@subgroup), I don't quite get from your question what the processing you do is (record first and last in group and sum fields?). Anyway - your gap finding is missing, and you need to add logic for the two different kinds of gaps before you can summarize.