2. Let $a$ be a real root of the equation $x^{2}-2002 x+1=0$. Then $a^{2}-2001 a+\frac{2002}{a^{2}+1}=$ $\qquad$ .
2.2001 .
$\because \alpha$ is a real root of the equation $x^{2}-2002 x+1=0$, then
$$
\begin{array}{l}
\alpha^{2}-2002 \alpha+1=0 . \\
\therefore \alpha+\frac{1}{\alpha}=2002 .
\end{array}
$$

Therefore, $\alpha^{2}-2001 \alpha+\frac{2002}{\alpha^{2}+1}=\alpha-1+\frac{1}{\alpha}=2001$.