Example 2 Given that $x, y$ are positive integers, and $x y+x+y=23, x^{2} y+x y^{2}=120$. Then $x^{2}+y^{2}=$ $\qquad$
Solve: From $x y+x+y=23$, we can set $x y=\frac{23}{2}+t, x+y=\frac{23}{2}-t$.
Multiplying the two equations gives
$$
x^{2} y+x y^{2}=\left(\frac{23}{2}\right)^{2}-t^{2}=120 \text{. }
$$

Solving for $t$ yields $t= \pm \frac{7}{2}$.
Since $x$ and $y$ are both positive integers, when $t=\frac{7}{2}$, we have $x+y=8, x y=15$;

When $t=-\frac{7}{2}$, we have $x+y=15, x y=8$ (discard this case). Therefore, $x^{2}+y^{2}=(x+y)^{2}-2 x y=34$.