Consider a text file that looks like this

-----------------------------------------------------------------

ABC this is the first line

XYZ this is the second line or line 2

MNO this is the catch

POD this is a line

NFY this is a line

POR this is a line

LKM this is a line

ABC this is a line

XYZ this is a line

MNO this is a line

EFG this is the catch

NFY this is a line

POR this is a line

LKM this is a line

ABC this is the first line

XYZ this is the second line or line 2

MNO this is the catch

ABC this is a line

XYZ this is a line

MNO this is a line

EFG this is the catch

----------------------------------------------

Now these lines are divided into two sets.

If the pattern of the first 3 letters in the line go as, firstly case 1

ABC

XYZ

MNO

And case 2 is when specifically EFG occurs as the 4th line after ABC XYZ and MNO.

I'm looking to store the counts of the occurence of case 1 and 2 using perl. It should be noted that ABC XYZ and MNO will always occur in the same sequence and the only catch would be the occurence of EFG which must be noted. the logic I'm using is to check for the occurence of EFG by tracing the end of the MNO line for the new line \n occurence. But for some reason this is not working. Can someone help me with the code for this requirement. Thanks!