5. Let the line $y=k x-2$ intersect the parabola $y^{2}=8 x$ at points $A$ and $B$. If the x-coordinate of the midpoint of segment $A B$ is 2, then the length of segment $A B$ is $|A B|=$ $\qquad$ .
5. $2 \sqrt{15}$.

According to $k x=y+2$, we get
$$
\begin{array}{l}
k y^{2}=8 k x=8 y+16, \\
y_{1,2}=\frac{4}{k} \pm \frac{4}{k} \sqrt{k+1} .
\end{array}
$$

Thus, $x_{1,2}=\frac{2}{k}+\frac{4}{k^{2}} \pm \frac{4}{k^{2}} \sqrt{k+1}$.
According to the condition, we have
$$
2=\frac{x_{1}+x_{2}}{2}=\frac{2}{k}+\frac{4}{k^{2}} \Rightarrow k=2 \text { or }-1 \text {. }
$$

If $k=-1$, from equations (1) and (2), we know that the line intersects the parabola at a unique point $(2,-4)$, which is a contradiction.
If $k=2$, from equations (1) and (2), we get the intersection points
$$
A(2+\sqrt{3}, 2+2 \sqrt{3}), B(2-\sqrt{3}, 2-2 \sqrt{3}) \text {. }
$$

In summary, $|A B|=2 \sqrt{15}$.