in reply to removing non-duplicates

my @lines = <>: my %count; $count{$_}++ for @lines; my @unique_lines = grep { $count{$_} == 1 } @lines; print for @unique_lines; # or whatever you do with the result
This solution does not require the input to be pre-sorted, and it preserves the original order of the lines printed.