Search notes:

Perl regular expressions: match between

The following example matches the texts between <ITEMS> and </ITEMS>
#!/usr/bin/perl
use warnings;
use strict;

my $text = 'abc <ITEMS>de fghi</ITEMS> j kl mno <ITEMS>pq r stu vw</ITEMS> xyz';

my @items = $text =~ m,<ITEMS>((?:(?!<ITEMS>).)*?)</ITEMS>,g;

print join "\n", @items;
#
# de fghi
# pq r stu vw
Github repository about-perl, path: /regular-expressions/match-between-1.pl
Apparently, this construct is also known as tempered greedy token (also this Stackoverflow answer).

See also

Perl regular expressions

Index