in reply to Substitute strings

I assume that you're interested in func1 followed by balanced parenthesis so this might be of use.
#!/usr/bin/env perl use strict; use warnings; my $balpar_re=qr/ ( \( # opening ( (?:[^'"()]++ # Not a ', ", ( or ) - no b +acktracking |(?:'(?:[^']|\')*?') #' a single quote string |(?:"(?:[^"]|\")*?") #" a double quote string |(?-1) # must be a ( or ) so recur +se )*+ # zero or more time - no ba +cktracking \) # closing ) ) /x; my $text=<<'__EOT__'; xfunc1("shouldn't be changed!") func1 (abc,"abc","should,be,changed!"); func1(arg(),narg()); __EOT__ if ($text=~ s{\bfunc1\s*$balpar_re}{newtext}g) { print $text; }; __DATA__

Replies are listed 'Best First'.
Re^2: Substitute strings
by AnomalousMonk (Archbishop) on Sep 12, 2016 at 18:00 UTC
        |(?-1)                         # must be a ( or ) so recurse

    kepler: Please note that the  (?-PARNO) regex operator is only available with Perl version 5.10 and above. Please see Extended Patterns in perlre.


    Give a man a fish:  <%-{-{-{-<