How can I match and store the various lines in this string in $1 , $2 and $3 variables in Perl?
$string = "This is a line 1.\nThis is line 2.\nThis is line 3.\n";
I know I have to use the /m modifier but so far my attempts have been unsuccessful.
I tried
$string =~ m/^(.*?)$.^(.*?)$.^(.*?)$/sm;
and other combinations to no avail. I want to keep it simple, so any answers pointing out mistakes would be helpful. I want to only try and use /s and /m modifiers.
OK I found it.
$.being treated as a variable was the clue. I used:and printed
$1,$3,$5.Thanks all.