my @ids = qw/ A1 A2 A3 B5 B6 B7 C789 C790 /; my @letters = sort keys %{ { map { substr($_,0,1), undef } @ids } }; print "Found the following letters: @letters\n"; __output__ Found the following letters: A B C