in reply to Why repeated matches...
Once your regex succeeds, $1 holds its value until the next time the regex *succeeds*. You want to conditionalize your use of $1 to only when the regex succeeds, not to when $1 is true:
while (my $line = <FH>) { next unless $line =~ m/\s([\w ]+? PRIMARY SCHOOL)/; push (@schools, $1); }
|
|---|