$/ = '.$/; my $prev_rec=''; while () { next if ($_ eq $prev_rec); $prev_rec = $_; # process $_ somehow as it is unique }