in reply to Counting matches and removing duplicates

You generally do that by storing all your data into a hashtable keyed on the properties you want to be unique. A hashtable stores tuples of (key,value). In this particular case the value is of no concern, only the key is important. That's why below the value is always 1. And let the hashtable do the hard work knowing the principle that hashtable's keys are unique. Here is an example:

use strict; use warnings; my %UH; $UH{'k1'} = 1; # hash contains 1 item $UH('k2'} = 1; # hash contains 2 items $UH{'k1'} = 1; # at this point the hash still contains 2 items for my $k (sort keys %UH){ print "Hash contains key '$k'\n"; }

If your data is stored in an array then you make items unique by creating a hashtable from the array (%{ {map { $_ => 1 } @items} }) and then taking the keys of that:

use strict; use warnings; my @items = ('ü','ü','ä', 'Ä'); my @unique_items = sort keys %{ {map { $_ => 1 } @items} }; print "@unique_items\n";

Note that sorting is optional of course.

Alternatively, you can use a perl module to do what you want, see e.g. here: https://perlmaven.com/unique-values-in-an-array-in-perl