use strict;
my $str = 'text|p1_1_1120170AS074192161A0Z20|C M E - Rectifier|@|text|p1_2_1120170AS074192161A0Z20|Huawei|@|text|p1_3_1120170AS074192161A0Z20|Rectifier Module 3KW|@|text|p1_4_1120170AS074192161A0Z20|Shuangdeng 6-FMX-170|@|text|p1_5_1120170AS074192161A0Z20|24021665|@|text|p1_6_1120170AS074192161A0Z20|1120170AS074192161A0Z20|@|text|p1_7_1120170AS074192161A0Z20|OK|@|text|p1_8_1120170AS074192161A0Z20||@|text|p1_9_1120170AS074192161A0Z20|ACTIVE|@|text|p1_10_1120170AS074192161A0Z20|-OK|@|text|site_id|20MJK110|@|text|barcode_flag|auto|@|text|movement_flag||@|text|unit_of_measurement||@|text|flag_waste|no|@|text|req_qty_db|2|@|text|req_qty|2
text|p1_1_1120170AS074192161A0Z20||@|text|p1_2_1120170AS074192161A0Z20|Huawei|@|text . . .';
my $regex = qr/^.*?p1_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