use strict; use warnings; my @arr = (); open(IFH, "<", "data.txt"); my $cur = scalar ; push @arr, $cur; # @arr contains, at most, N identical lines # .ie if "d1d" occurs five times in a row, then # @arr will contain the 5 occurrences of "d1d" # @arr is reset to one element as new strings # are encountered while($cur = ) { if ($cur eq $arr[0]) { push @arr, $cur; } else { # if here, we have a new string, so check # the size of @arr to see if current string is unique print $arr[0] if scalar(@arr) == 1; @arr = ($cur); } } print $arr[0] if scalar(@arr) == 1; close IFH; __OUTPUT__ b1b e1e f1f i1i j1j