in reply to While two conditions

my $text = 'perl monks'; my $query = qr{ (?<M>monk) (?(<M>)(?{do_something_different()})) | (?<P>perl) (?(<P>)(?{do_something()})) }x; while($text =~ /$query/gi){}; sub do_something{ print "found perl\n"; } sub do_something_different{ print "found monk\n"; }

Replies are listed 'Best First'.
Re^2: While two conditions
by welle (Beadle) on May 01, 2012 at 14:17 UTC

    It looks like it could be something for me, BUT - excuse my ignorance - waht kind of sintax is this:

    my $query = qr{ (?<M>monk) (?(<M>)(?{do_something_different()})) | (?<P>perl) (?(<P>)(?{do_something()})) }x;

    With perl 5.8.9 it just doesn't work