$str = "(a a (a a)(a a))(b b(b)b b)" and have my ($parens, $rest) = match($str) ;