in reply to Read file line by line and check equal lines

  1. use strict and use warnings.
  2. I don't think that your trick of $line % 2 == 0 can work; both singles and pairs can occur on even or odd lines.
  3. If you "pre-load" $prev before you begin your while(<>){...} loop, you can avoid keeping track of $line == 1 and $line >= 2.

Here is my (loosely tested) version: #!perl use strict; use warnings; my $last_line = <DATA>; my $seen_count = 1; while (<DATA>) { if ( $last_line ne $_ ) { print $last_line if $seen_count == 1; $last_line = $_; $seen_count = 0; } $seen_count++; } print $last_line if $seen_count == 1; __END__ a1a a1a b1b c1c c1c d1d d1d e1e f1f g1g g1g h1h h1h i1i j1j