in reply to Comparing adjacent lines

Okay, this one’s easy.   You simply need another variable, which will be used to contain the contents of the previous line seen.   You store the value of the current record (e.g. $_) into this variable at the end of the while-loop.

During the first iteration through the loop, the value of this variable will be “undefined,” i.e. undef, which you can test for using the function, defined().   During this iteration, there will be no “previous line” to compare to, so you omit that part.