in reply to Re^2: print a determinate line number
in thread print a determinate line number

if the following line is different from the previous i have to print it

For that, you'd have to keep the previous line:

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

(The defined check would skip the first line, as there isn't really one previous to it...)