Example 6 Find all prime numbers $p$ such that $\frac{2^{p-1}-1}{p}$ is a perfect square.

Find all prime numbers $p$ such that $\frac{2^{p-1}-1}{p}$ is a perfect square.
Let $p$ be a prime number that satisfies the condition, then obviously $p$ is an odd prime. By Fermat's Little Theorem, we have

Thus,
$$\begin{array}{c}
p \mid 2^{p-1}-1 \\
2^{p-1}-1=\left(2^{\frac{p-1}{2}}-1\right)\left(2^{\frac{p-1}{2}}+1\right) \\
p \left\lvert\, 2^{\frac{p-1}{2}}-1\right. \text { or } p \left\lvert\, 2^{\frac{p-1}{2}}+1\right.
\end{array}$$

Since $\left(2^{\frac{p-1}{2}}-1,2^{\frac{p-1}{2}}+1\right)=\left(2^{\frac{p-1}{2}}-1,2\right)=1$, one of $p \left\lvert\, 2^{\frac{p-1}{2}}-1\right.$ and $p \left\lvert\, 2^{\frac{p-1}{2}}+1\right.$ must hold.

If $p \left\lvert\, 2^{\frac{p-1}{2}}-1\right.$, then by the condition and $\left(2^{\frac{p-1}{2}}-1,2^{\frac{p-1}{2}}+1\right)=1$, there exists a positive integer $x$ such that

At this point,
$$\begin{array}{c}
2^{\frac{p-1}{2}}+1=x^{2} \\
(x-1)(x+1)=2^{\frac{p-1}{2}}
\end{array}$$

This indicates that $x-1$ and $x+1$ are both powers of 2, and $x$ is odd, so $x-1$ and $x+1$ are two consecutive even numbers. Therefore, it can only be
$$x-1=2, x+1=4$$

Thus,
$$\begin{array}{l}
x=3 \\
p=7
\end{array}$$

If $p \left\lvert\, 2^{\frac{p-1}{2}}+1\right.$, then similarly, there exists a positive integer $x$ such that
$$2^{\frac{p-1}{2}}-1=x^{2},$$

When $p>3$, this leads to
$$x^{2}=2^{\frac{p-1}{2}}-1 \equiv-1(\bmod 4)$$

which is a contradiction, so $p=3$.
On the other hand, when $p=3$ and 7, $\frac{2^{p-1}-1}{p}$ are 1 and 9, respectively, both of which are perfect squares. In summary, $p=3$ or 7.