Let $G_1$ and $G_2$ be two finite perfect groups such that $G_1 / Z(G_1) \cong G_2 / Z(G_2)$. Then there exists a finite perfect group $G$ and subgroups $Z_1, Z_2 \le Z(G)$ with $$ G / Z(G) \cong G_i / Z(G_i) \quad \mbox{and} \quad G / Z_i \cong G_i, \quad i = 1,2. $$
I want to construct the group $G$. I tried to start from the direct product $G_1 \times G_2$ and factor out an appropriate normal subgroup, but everything I try does not give the desired properties. And also I have no idea how to incorporate the assumption that $G_1$ and $G_2$ are perfect. So any hints on this exercise?
This exercise is taken from the book Theory of finite groups by H. Kurzweil and B. Stellmacher, and appears there on page 36.

This is just an outline argument, not a full solution.
Let $X= G_1/Z(G_1) \cong G_2/Z(G_2)$ and let $\rho_1$, $\rho_2$ be the associated epimorphisms $\rho_1:G_1 \to X$ and $\rho_2:G_2 \to X$.
Now let $H = \{ (g_1,g_2) \in G_1 \times G_2 \mid \rho_1(g_1) = \rho_2(g_2) \}$ and put $G = [H,H]$. Note that $G$ is perfect by 1.5.3 in the book, and $G$ projects onto both $G_1$ and $G_2$.