http://www.perlmonks.org?node_id=930650


in reply to extract a substring between two emements

>perl -wMstrict -le "my $line = 'Hello hello START this is comment END ' . 'START this is still comment END ' . 'START this should still be comment END ' . 'this is fixed' ; ;; my $START = qr{ START \s* \K }xms; my $END = qr{ (?= \s* END) }xms; my $not_end = qr{ (?! $END) . }xms; ;; my ($extract) = $line =~ m{ $START $not_end* should $not_end* $END }xmsg; print qq{[[$line]]}; print qq{'$extract'}; " [[Hello hello START this is comment END START this is still comment END START this should still be comment END this is fixed]] 'this should still be comment'