Not all the fields matches. Field $2 $4 $5 do not match the next row in the output.

Well, field 2 is either BUY or SELL, which is a good thing, because otherwise you can't correlate the lines. Fields 4 and 5 are just the reverse, but are you interested in their content? I think you need only fields 1, 3 and 6 for identifying the transaction, provided it is really the case - as you seem to assume - that things are sold always on the same day as they are bought, which is, IMO, a strange assumption.

For analyzing the lines, I would first split them into individual fields. Perhaps it is best to first extract field 2 (because this field is different, in that it can contain embedded spaces, and is delimited by quotes), and then use split to split the remaining line into individual fields. You can then use for your comparision between two successive rows exactly those fields you are interested in.

Just split your line on spaces into an array @previous, read next line and split it into @current, compare the relevant fields between current and previous, print the whole array (or line or whatever you want to print exactly) if the relevant fields match. Then copy @current onto @previous, read next line, split it to @current and so on in a loop.