use strict; my $string = 'bar a2 b2 c3 d3 d4 a1 f2 f3'; my $flag = 0; foreach(split(/\s+/, $string)) { $flag++, last if /\w\d/; } print "foo's found in list\n" if $flag; #### use strict; my @foos = qw(d4 b2); my $string = 'bar a2 b2 c3 d3 d4 a1 f2 f3'; my $flag = 0; foreach my $cand (split(/\s+/, $string)) { foreach(@foos) { $flag++, last if $cand =~ /$_/; } } print "foo's found in list\n" if $flag;