in reply to extract substring between token a and token b

If the string you want to match spans more than one line, you need to use the /s modifier, because otherwise the dot doesn't match the newline character.

If you do the pattern matching in list context with the /g (global) option, you can capture all the matches in one array without using $1. e.g., @matches = $text =~ /(pattern)/g;