$ perl -i.bak -lne 's/\A\s+//; s/\s+\Z//; next unless $_ and not $seen{$_}++; print' input.txt