in reply to Last undefines a for loop's itererator?

This might do what you want:
#!/usr/bin/perl use strict; use warnings; my $match = '1995_Olga_goes_to_Egypt'; my @pictures = qw{1996/1996_Olga_goes_to_Egypt/QD0017005.JPG 1995/1995 +_Olga_first_time_in_Cyprus/06330004.JPG 1995/1995_Olga_goes_to_Egypt/QD0017004.JPG}; my $picture; foreach (sort @pictures) { print "Debug: $_\n"; if (m/$match/) { print "Matched, $_\n"; $picture = $_; last; } } print "Result: $picture\n";
This assigns only the first matched element of @pictures to the lexical my $picture before dropping out of the loop.