c:\@Work\Perl\monks\iaw4>perl -wMstrict -le "use 5.010; ;; my $s = 'ab + (fun1( fun2( 3 +fun3 ( 4+(5+6) ))) ) + x + f ( 1 + 2 )'; print qq{'$s'}; ;; $s =~ s{ [(] (?: [^()]++ | (?0) )* [)] } { (my $ns = ${^MATCH}) =~ s/\s+//g; $ns; }xmsgpe; print qq{'$s'}; " 'ab + (fun1( fun2( 3 +fun3 ( 4+(5+6) ))) ) + x + f ( 1 + 2 )' 'ab + (fun1(fun2(3+fun3(4+(5+6))))) + x + f (1+2)'