#!/usr/bin/perl use strict; use warnings; use Smart::Comments; print "\n" x5; my ($np_1,$np_2); # The initial balance parentheses expression with an embedded set is: # $np=qr/\( ([^()] | (??{$np})) *\)/x; # And quoted strings are "(?:[^"]|\")*" and '(?:[^']|\')*' or ('|")(?:[^\1]|\\1)*\1 so $np_1=qr/ \( # The opening "(" ((?: # We'll want this hence the capturing () | [^'"()] #' not a ' " ( or ) | (?:'(?:[^']|\')*?') #' a single quote string | (?:"(?:[^"]|\")*?") #" a double quote string | (??{$np_1}) # parenthesized expression )*) \) # and the closing ")" /x; # Deal with the argument list $np_2=qr/ ( # We'll want this hence the capturing () (?: # [^'"(),] #' not a ' " ( ) or , | (?:'(?:[^']|\')*?') #' a single quote string | (?:"(?:[^"]|\")*?") #" a double quote string | $np_1 # parenthesized expression see above )* )(,|\z) # termining , or \z /x; my $string=q{other stuff &COMPAREEQUAL(First-param.one,'(,',Third-param); more stuff other stuff &COMPAREEQUAL(one(foo('bar'))+two(foobar),'(,',Third-param); more stuff dude() }; ### $string while ($string =~ m/\b(\w+)\s*$np_1/g) { my ($subroutine_name,$argument_list)=($1,$2); ### $subroutine_name ### $argument_list while ($argument_list =~ m/$np_2/g and $1) { ### argument: $1 }; }; __END__