use strict; use warnings; my $match = '1995_Olga_goes_to_Egypt'; my @pictures = qw{1995/1995_Olga_first_time_in_Cyprus/06330004.JPG 1995/1995_Olga_goes_to_Egypt/QD0017004.JPG}; foreach my $picture (sort @pictures) { print "Debug: $picture\n"; if ($picture =~ m/$match/) { print "Matched, $picture\n"; last; } } print "Result: $picture\n";