$str = "((A AND B) OR (C AND D) NOT E)"; print "$1\n" while( $str =~ /\(([\w\s]+)\)/g);