in reply to regex excluding some matches

#!/usr/bin/perl use warnings; use strict; my $line = '|Match_regex_1a_P_a|Match_regex_2_a|Match_regex_1b_P_b|Mat +ch_regex_2_b|'; my $regex1 = qr/\|(?<DataCapture>[^|]+)_P_/; my $regex2 = qr/\|(?<DataCapture>(?![^|]+_P_)[^|]+)/; use Test::More; my @matches1 = map "Match_regex_1$_", qw( a b ); while ($line =~ /$regex1/g) { is $+{DataCapture}, shift @matches1; } my @matches2 = map "Match_regex_2_$_", qw( a b ); while ($line =~ /$regex2/g) { is $+{DataCapture}, shift @matches2; } done_testing();

Where

[^|]+_P_

matches exactly what you want to avoid.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]