foreach my $pattern (@patterns) { if (substr($fields[7],0,length($pattern)) eq $pattern) { ### Code here last; } }