I would like to get a substring between two delimiters (regular expressions) from a string. I want to use this:
while (<>) { if (/START/../END/) { next if /START/ || /END/; print; } }
But this works on stdin lines. I would like to make it work on line by line lines. How?
If you want to process a line that already contains several lines, use split:
foreach (split(/\n/, $str)) { if (/START/../END/) { next if /START/ || /END/; print; } }
Simply:
my ($between) = $string =~ /START(.*?)END/s;
Alternatively, read from the line:
use 5.010; open my $string_fh, "<", \$string or die "Couldn't open in-memory file: $!"; while ( <$string_fh> ) { ...
. , , $/ (, " undef ), .
$/
. "" @perldoc