my @text = split /\s+/, $text; my @results; for (@text){ push @results, $1 if m/\b($expr)\b/; }