I have a string that covers several lines. I need to extract the text between two strings. For example:
Start Here Some example
text covering a few
lines. En
Use the /s regex modifier to treat the string as a single line:
/s Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.
$string =~ /(Start Here.*)End Here/s;
print $1;
This will capture up to the last End Here, in case it appears more than once in your text.
If this is not what you want, then you can use:
$string =~ /(Start Here.*?)End Here/s;
print $1;
This will stop matching at the very first occurrence of End Here.