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;