use strict;
my $str = '|poke|p1|Volcarona, M|
|poke|p1|Urshifu-*, F|
|poke|p1|Magnezone|
|poke|p1|Tangrowth, M|
|poke|p1|Corviknight, F|
|poke|p1|Hippowdon, F|
|poke|p2|Togekiss, M|
|poke|p2|Kommo-o, M|
|poke|p2|Jirachi|
|poke|p2|Mimikyu, F|
|poke|p2|Dragalge, F|
|poke|p1|Dragapult, F|
|poke|p1|Hatterene, F|
|poke|p1|Flygon, F|
|poke|p1|Inteleon, F|
|poke|p1|Obstagoon, F|
|poke|p1|Arcanine, F|
|poke|p2|Pincurchin, F|
|poke|p2|Magnezone|
|poke|p2|Hawlucha, F|
|poke|p2|Raichu-Alola, M|
|poke|p2|Ferrothorn, M|
|poke|p2|Magearna-Original|
|poke|p1|Slowbro, M|
|poke|p1|Tangrowth, F|
|poke|p1|Crawdaunt, F|
|poke|p1|Dragapult, M|
|poke|p1|Clefable, M|
|poke|p1|Excadrill, M|
|poke|p2|Togekiss, F|
|poke|p2|Starmie|
|poke|p2|Urshifu-*, M|
|poke|p2|Amoonguss, M|
|poke|p2|Cinderace, F|
|poke|p2|Jirachi|';
my $regex = qr/\|poke\|p([1,2])\|(.+?)(,|\|)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html