5. In the Cartesian coordinate system, line $l$ passes through one of the foci of the hyperbola $x^{2}-y^{2}=1$ and intersects the hyperbola at points $A$ and $B$. If the circle with $A B$ as its diameter is tangent to the $y$-axis, then $|A B|=$ $\qquad$ .
$5.2+2 \sqrt{2}$. 
It is known that the two foci of the hyperbola $x^{2}-y^{2}=1$ are $( \pm \sqrt{2}, 0)$.
Without loss of generality, assume the line $l$ passes through the right focus $(\sqrt{2}, 0)$.
(1) When $A B$ is not perpendicular to the $x$-axis, let the equation of the line $l$ be $y=k(x-\sqrt{2})$. Substituting this into the hyperbola equation and simplifying, we get
$$
\left(1-k^{2}\right) x^{2}+2 \sqrt{2} k^{2} x-\left(2 k^{2}+1\right)=0.
$$

Clearly, $k \neq \pm 1$.
Let $A\left(x_{1}, y_{1}\right), B\left(x_{2}, y_{2}\right)$. Then $x_{1} 、 x_{2}$ are the two roots of the above quadratic equation.
By Vieta's formulas, we have
$$
x_{1}+x_{2}=\frac{2 \sqrt{2} k^{2}}{k^{2}-1}, x_{1} x_{2}=\frac{2 k^{2}+1}{k^{2}-1}.
$$

Thus, by the chord length formula, we get
$$
\begin{array}{l}
|A B|=\sqrt{1+k^{2}}\left|x_{1}-x_{2}\right| \\
=\sqrt{1+k^{2}} \cdot \frac{\sqrt{\left(2 \sqrt{2} k^{2}\right)^{2}+4\left(1-k^{2}\right)\left(2 k^{2}+1\right)}}{\left|1-k^{2}\right|} \\
=\frac{2\left(k^{2}+1\right)}{\left|1-k^{2}\right|}.
\end{array}
$$

On the other hand, the distance from the midpoint $M$ of segment $A B$ to the $y$-axis is
$$
d=\left|\frac{x_{1}+x_{2}}{2}\right|=\frac{\sqrt{2} k^{2}}{\left|k^{2}-1\right|}.
$$

If the circle with diameter $A B$ is tangent to the $y$-axis, then
$$
|A B|=2 d,
$$

i.e., $\frac{2\left(k^{2}+1\right)}{\left|1-k^{2}\right|}=2 \cdot \frac{\sqrt{2} k^{2}}{\left|k^{2}-1\right|}$
$$
\begin{array}{l}
\Rightarrow k^{2}=1+\sqrt{2} \\
\Rightarrow|A B|=\frac{2\left(k^{2}+1\right)}{\left|1-k^{2}\right|}=2+2 \sqrt{2}.
\end{array}
$$
(2) When $A B$ is perpendicular to the $x$-axis, the equation of the line $l$ is $x=\sqrt{2}$, and the coordinates of points $A$ and $B$ are $(\sqrt{2}, \pm 1)$. The distance from the midpoint $M$ of $A B$ to the $y$-axis is $d=\sqrt{2}>1$, which does not meet the condition of tangency.
In summary, the length of segment $A B$ is $2+2 \sqrt{2}$.