my $prev; while (<>) { print if defined($prev) and $_ ne $prev; $prev = $_; # update $prev }