RULES a ([()])(?!_[0-9])=e=>$1."_".($1 eq "(" ? ++$n : --$n)."_" ENDRULES while(<>){print a($_)} =head1 number parentesis (put a number in each "(" ou ")" Where =e=> ... means: substitute by the result of evar of ...