#!/usr/bin/perl -w %common = map { lc $_, 1 } qw/ a and the /; @words = qw/ hello there Hello hello the a A /; @words = sort keys %{+{ map { !$common{$_ = lc $_} ? ($_, 1) : () } @words }}; print "@words\n";