my @nc; my $last; while (<$fh>) { chomp; push @nc, $last = $_ if !defined($last) || $last ne $_; }