my %seen; my @order = grep { !$seen{$_}++ } $test_string =~ /([abcd])/g;