use strict; use warnings; my $string="TestVar(Test1->(xy))->Var2(Test2(10)(12))->Finalvar"; while ($string=~s/ # repeat while we make matches \( #beginning of a parenthesised group [^)(]+ # non parentheses charaters \) # end of group //gx) {} print "$string\n";