  A perfect code in a graph $\Gamma$ is a subset $C$ of $V(\Gamma)$ such that
no two vertices in $C$ are adjacent and every vertex in $V(\Gamma)\setminus C$
is adjacent to exactly one vertex in $C$. Let $G$ be a finite group and $C$ a
subset of $G$. Then $C$ is said to be a perfect code of $G$ if there exists a
Cayley graph of $G$ admiting $C$ as a perfect code. It is proved that a
subgroup $H$ of $G$ is a perfect code of $G$ if and only if a Sylow
$2$-subgroup of $H$ is a perfect code of $G$. This result provides a way to
simplify the study of subgroup perfect codes of general groups to the study of
subgroup perfect codes of $2$-groups. As an application, a criterion for
determining subgroup perfect codes of projective special linear groups
$\mathrm{PSL}(2,q)$ is given.
