Example 37 (2006 Thailand Mathematical Olympiad) Find all prime numbers $p$ such that $\frac{2^{p-1}-1}{p}$ is a perfect square.
For each prime $p$, let
$$
f(p)=\frac{2^{p-1}-1}{p} \text {. }
$$

We will prove that when $p>7$, $f(p)$ is not a perfect square.
Assume there exists a prime $p>7$ such that $2^{p-1}-1=p m^{2}$ (where $m$ is an integer), then $m$ must be odd.
We will discuss two cases.
(1) $p=4 k+1(k>1)$,

then $2^{4 k}-1=(4 k+1) m^{2} \equiv 1(\bmod 4)$.
But $2^{4 k}-1 \equiv 3(\bmod 4)$, which is a contradiction.
(2) $p=4 k+3(k>1)$,

then $2^{4 k+2}-1=\left(2^{2 k+1}-1\right)\left(2^{2 k+1}+1\right)=p m^{2}$.
Considering $\left(2^{2 k+1}-1,2^{2 k+1}+1\right)=1$, we will discuss two sub-cases.
(i) Suppose $2^{2 k+1}-1=u^{2}, 2^{2 k+1}+1=p v^{2}$.

Since $k>1$, then $2^{2 k+1}+1 \equiv 1(\bmod 4)$.
But $p v^{2} \equiv 3 \times 1 \equiv 3(\bmod 4)$, which is a contradiction.
(ii) Suppose $2^{2 k+1}-1=p u^{2}, 2^{2 k+1}+1=v^{2}$, then $2^{2 k+1}=v^{2}-1=(v-1)(v+1)$.
Therefore, $v-1=2^{s}, v+1=2^{t}(s1$ assumption, leading to a contradiction.
In summary, when $p>7$, $f(p)$ is not a perfect square.
By enumeration, we verify the cases for $p=2,3,5,7$, and find that $p=3$ and $p=7$ satisfy the condition.