Hashes are a good way to handle uniqueness. Look up "hash of arrays".
Here is some code that illustrates some of what you want.
#!/usr/local/bin/perl -w
use 5.010;
use strict;
### code from here ###
my @classedSources = (
"hitdb/CustomerPartner/Opten/Scripts/Daily/egy_batch.sql",
"hitdb/CustomerPartner/Opten/Scripts/Daily/megegy_batch.sql",
"hitdb/CustomerPartner/Opten/Scripts/Other/cp_OptenTruncTables.sql",
"hitdb/CustomerPartner/Opten/Scripts/Other/htcp_firm_loadAll.sql",
"hitdb/CustomerPartner/Opten/Scripts/Other/runHT_CP_EKN.sql",
"hitdb/CustomerPartner/Opten/Scripts/Other/runHT_CP_FIRM.sql",
"hitdb/Policy/Views/Types/HtTypoWsAlaTarifFE1.sql",
"hitdb/Policy/Types/HtTypoWsHobMfactorFE1.sql",
"hitdb/Policy/Types/HtTypoWsCoverAlaFE1.sql",
"hitdb/Policy/Views/Types/HtTypoWsCoverAlaFE1.sql",
"hitdb/Policy/Types/HtTypoWsCoverAlaListFE1.sql",
"hitdb/Policy/Views/Types/HtTypoWsCoverAlaListFE1.sql",
"hitdb/Security/Scripts/ht_tut_mail_address_ws.sql",
"hitdb/Policy/Views/Types/HtTypoWsHobMfactorFE1.sql",
"hitdb/Accounting/Scripts/ht_tut_mail_address_ws.sql",
"hitdb/Policy/Scripts/ht_tut_mail_address_ws.sql",
"hitdb/Policy/Types/HtTypoWsAlaTarifFE1.sql",
"hitdb/astools/as#arch/Setup/Scripts/ht_tut_mail_address_ws.sql"
);
my %hash;
# this loop parses the array, splitting entries into path and filename
# then populating a hash of arrays keyed on filename
foreach (@classedSources) {
my ($path,$file) = $_ =~ /(.*\/)(.*)/;
push @{ $hash{$file} }, $path;
}
# parse the hash of arrays listing out the paths for each filename
foreach my $file (sort keys %hash) {
my @array = @{$hash{$file}};
say $file;
foreach my $path (@array) { say "\t$path" }
}