my %seen; while ( ) { s/\s+$//; # Remove trailing spaces and newline. print "$_\n" unless $seen{$_}++; }