5. Let $n \geqslant 3$ be a positive integer. Find the maximum number of diagonals that can be selected from a regular $n$-gon such that any two of the selected diagonals either do not intersect in the interior or are perpendicular to each other.
5. If $n$ is even, the maximum number of diagonals that can be selected is $n-2$; if $n$ is odd, the maximum number of diagonals that can be selected is $n-3$.
(1) If $n$ is odd, there do not exist two diagonals that are perpendicular to each other.

Indeed, if there exist four vertices $A, B, C, D$ of a regular $n$-gon such that $AB \perp CD$, let $E$ be a point on the perpendicular bisector of $AB$ and also a vertex of the regular $n$-gon, and let $E'$ be the point diametrically opposite to $E$ on the circumcircle of the regular $n$-gon, as shown in Figure 1.

Since $EC = E'D$ and $C, D, E$ are vertices of the regular $n$-gon, $E'$ must also be a vertex of the regular $n$-gon. This contradicts the fact that among all the odd-numbered vertices of a regular $n$-gon, there do not exist a pair of diametrically opposite points.
Thus, we only need to consider the case where the diagonals do not intersect.

When the number of selected diagonals reaches the maximum value, these diagonals should divide the regular $n$-gon into $n-2$ triangles. Therefore, the maximum number of diagonals that can be selected is $n-3$, and this maximum value can be achieved. For example, consider all the diagonals drawn from a single vertex, which total $n-3$ diagonals and satisfy the condition, as shown in Figure 2.
(2) If $n$ is even, and if any two of the selected diagonals do not intersect, then by (1), the maximum number of selected diagonals is $n-3$.

Assume there exist two selected diagonals that are perpendicular to each other. Consider the set $S$ of diagonals that are parallel to one of these two diagonals and intersect with some selected diagonal, and assume $S$ contains $k$ diagonals, and these $k$ diagonals have $l$ distinct endpoints.

First, consider the longest diagonal in one direction among the diagonals in set $S$. Then, the other diagonals in $S$ do not originate from the endpoints of this longest diagonal, otherwise, the diagonal originating from the endpoints of the longest diagonal would intersect with a longer diagonal in $S$ (as shown in Figure 3), which is a contradiction.
Similarly, for the other direction, the same conclusion can be drawn.
Removing these two longest diagonals and their four endpoints, we are left with $k-2$ diagonals and $l-4$ endpoints, and each endpoint belongs to at most two diagonals.
Then, $2(l-4) \geq 2(k-2) \Rightarrow k \leq l-2$.
Next, consider the set of adjacent vertices of the regular $n$-gon, such that each boundary vertex of these sets is an endpoint of a diagonal in set $S$, and the internal points are not endpoints of any diagonal in $S$. There are $l$ such sets, and we denote these sets as $P_{1}, P_{2}, \cdots, P_{l}$.
We will prove that any selected diagonal not in set $S$ must connect two vertices within the same set $P_{i}$.

Assume there exists a selected diagonal $d$ not in set $S$, and its two endpoints are in different sets $P_{i}$ and $P_{j}$. Let $d_{1}, d_{2}$ be two diagonals in set $S$, each having one endpoint as a boundary point of $P_{i}$. Then, $d$ either intersects with $d_{1}$ or $d_{2}$, or intersects with a diagonal in $S$ that is perpendicular to both $d_{1}$ and $d_{2}$, as shown in Figures 4 and 5.
By the definition of set $S$, $d \in S$, which is a contradiction.
Within the same set $P_{i}$, since the vertices belong to the same side of the diameter of the circumcircle of the regular $n$-gon, there are no perpendicular diagonals. Therefore, in $P_{i}$, at most $\left|P_{i}\right|-2$ diagonals can be selected, where, when $\left|P_{i}\right|>2$, it includes the diagonal connecting the two boundary vertices of $P_{i}$.
Thus, the maximum number of selected diagonals is
$\sum_{i=1}^{l}\left(\left|P_{i}\right|-2\right)+k=\sum_{i=1}^{l}\left|P_{i}\right|-2 l+k$
$=(n+l)-2 l+k=n-l+k \leq n-2$.
The following example shows that this upper bound can be achieved.
For any vertex $A$ of a regular $n$-gon, let $A'$ be another point on the regular $n$-gon such that $AA'$ is a diameter of the circumcircle of the regular $n$-gon. Select all the diagonals drawn from point $A$ and the diagonal
$d'$, where $d'$ connects the two vertices adjacent to $A'$, as shown in Figure
6. Then, only one diagonal
$AA'$ and $d'$ intersect, and
are perpendicular to each other, and
these diagonals total $n-2$.
Therefore, the maximum number of diagonals that can be selected is $n-2$.