foreach (split "\n", $web) { if (m/(log_id\=(\d*)\&.*?Label Defect)/m) { #... etc } }