5. Given a unit cube $A B C D-E F C H$ with moving points $Q 、 P$ on edge $A D$ and line $B C$ respectively. If the line segment $M N$ obtained by the intersection of $\triangle P Q G$ and $\triangle B D E$ has a length of $y$, and $A Q$ $=x(0 \leqslant x \leqslant 1)$. Then the minimum value of $y$ expressed as a function of $x$ is $\qquad$
5. $y=\frac{\sqrt{6}}{2}-\frac{\sqrt{6}}{3-x}$.

When $A Q=x$, let $G Q$ intersect the plane $B D E$ at point $N$, draw $N M \perp B D$ at point $M$, connect $Q M$ to intersect line $B C$ at point $P^{\prime}$, and take point $P^{\prime}$ as $P$. It is known that at this time $y=|M N|$ is minimized.

Establish a spatial rectangular coordinate system as shown in Figure 3, then $Q(0, x, 1)$ and the points $(x, y, z)$ on the plane of $\triangle B D E$ satisfy $x+y=z$. Therefore, we can let $N\left(x_{0}, y_{0}, x_{0}+y_{0}\right)$.

Since point $N$ is on $Q G$, there exists $\lambda$ in $(0,1)$ such that $Q N=\lambda Q G$.
Substituting and eliminating $\lambda$ yields
$$
2 x_{0}+y_{0}=1, x_{0}(x-1)+y_{0}=x \text {. }
$$

Thus, $x_{0}=\frac{1-x}{3-x}, y_{0}=\frac{1+x}{3-x}$.
Therefore, $N=\left(\frac{1-x}{3-x}, \frac{1+x}{3-x}, \frac{2}{3-x}\right)$.
Since point $M$ is on $B D$, let
$$
M\left(x_{1}, 1-x_{1}, 1\right) \text {. }
$$

By $\boldsymbol{M N} \cdot \boldsymbol{B D}=0$, we know $x_{1}=\frac{3}{2}\left(\frac{1-x}{3-x}\right)$.
Thus, $y=|M N|=\frac{\sqrt{6}}{2}\left(\frac{1-x}{3-x}\right)=\frac{\sqrt{6}}{2}-\frac{\sqrt{6}}{3-x}$.