#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use File::Basename; my %filenames; my @files = map{[basename($_),(split /\./,basename($_))[0,5]]}glob "$pfad*Filter*.Endung"; my @allowed_strings = qw(AB12 CD34); for my $file(@files){ my @same_jobs = grep{$_->[1] eq $file->[1] and $file->[0] ne $_->[0]}@files; @filenames{@same_jobs} = (); } print Dumper([keys %filenames]);