my $last; my $i = 0; while () { chomp; $i++ if (!defined($last) || $_ ne $last); $last = $_; print OUT ("$_ $i\n"); }