You can't even use the named captures, as %+ is reset on each match, too. Fortunately, you can store the matching parts in variables - just make sure the assignment forces list context:
#!/usr/bin/perl use warnings; use strict; my @output = qw( Xmatch3X Xmatch4X Xmatch0Xmatch2X nomatch nomatch nomatchnomatch ); for my $x (0, 3) { if ($output[$x+2] !~ /.*match1.*/ and my ($m1) = $output[$x+2] =~ /.*(match2).*/ and my ($m2) = $output[$x] =~ /.*(match3).*/ and my ($m3) = $output[$x+1] =~ /.*(match4).*/ ){ print "Matched: $m1 $m2 $m3.\n"; } }
The parentheses after my are needed for the list context.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
In reply to Re: Perl Multiple If Conditions with Match Variables
by choroba
in thread Perl Multiple If Conditions with Match Variables
by razmeth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |