http://qs1969.pair.com?node_id=474270


in reply to create search string from array elements

If you want to be clever you could make an alternating pattern from the list of dates:

my $pat = join '|', @dates; my @files = grep /$pat/, @logfiles;

But I have no idea if that would be faster or slower than just doing a nested loop. A nested loop at least gives you the option of skipping the remainder when you've found a match.

my @files; foreach my $file( @logfiles ) { foreach my $date( @dates ) { if ( $file =~ /$date/ ) { push @files, $file; last; } } }