I am doing some text parsing using flip-flop operator and my data looks like below:
COMMAND START
CELL
123
COUNTER1    COUNTER2    COUNTER3
23          25          45
COUNTER1    COUNTER2    COUNTER3
22          34          52
CELL
234
COUNTER1    COUNTER2    COUNTER3
12          35          35
END
Now i need to iterate through this data and for each CELL, find the Sum of COUNTER2. Under each cell as we can see there might be 1 or more COUNTER rows. I tried using flip-flop operator like below, but its not working.
my ($CELL_ID_COL1, $TEMP_COUNT);
my @line_contents;
while (<>) {
    chomp;
    if(/^COMMAND.*START$/ .. /^END$/) {
        if (my $e1 = /^CELL$/ ... (/^CELL$/ || /^END$/)) {
            if ($e1 == 2) {
                @line_contents = split(/\s+/, $_);  #Split the line read on whitespaces
                $CELL_ID_COL1 = $line_contents[0];
                print "$CELL_ID_COL1\n";
                $TEMP_COUNT = 0;
            }
            if (my $e2 = /^COUNTER1.*COUNTER3$/ ...(/^COUNTER1.*COUNTER3$/ || /^CELL$/ || /^END$/) ) {
                print "$_\n";
                if ($e2 ==2) { 
                    @line_contents = split(/\s+/, $_);  #Split the line read on whitespaces
                    $TEMP_COUNT += $line_contents[1];
                }
                if ($e2 =~ /E0$/) {
                    redo;
                }
            }
            if ($e1 =~ /E0$/) {
                print "FINAL COUNT is: $TEMP_COUNT\n";              
                redo;
            }
        }
    }
}
I think this got to do something with the global state of flip-flop operator discussed in this question, but could not understand much. Please help me.
Thanks a lot in advance.