sub balanced { (my $s = shift) =~ s/[^()]//g; while ( $s =~s /\(\)// ){}; return $s ? 0 : 1; }