We consider an arbitrary pair of closed geodesics and the corresponding period integrals for the eigenfunctions of the Laplacian on a compact hyperbolic surface. A summation formula that relates geometric information about the geodesics (namely, the angles of intersection and lengths of common perpendiculars between them) to the period integrals is proved. As a corollary, an asymptotic is obtained for the second moment of the period integrals for a fixed geodesic as an average over the eigenvalue with an error term that can be interpreted in terms of the geometric data