my @array_code = qw(x-01 x-02 x-03 x-04 v-05 v-06 v-07 x-08 x-09 x-10 x-11); my $pattern = "(".join("|", @array_code ).")"; my @files = qw(1234567_x-01_2013_03.txt 1234667_x-03_2013_03.txt 0034567_y-01_2013_03.txt 1234567_v-01_2013_03.txt 233567_v-05_2013_03.txt 1234567_x-55_2013_03.txt); for my $file (@files) { next if $file =~ /$pattern/; print $file,"\n"; }