A finite basis set particularly adapted for solving the Hartree-Fock equation for diatomic molecules in prolate spheroidal coordinates has been constructed. These basis functions have been devised as products of B-splines times associated Legendre polynomials. Due to the large number of B-splines, the resulting set of eigenfunctions is amply distributed over excited states. This gives the possibility of using these basis sets to calculate sums over excited states, appearing in various orders of perturbation theory. As an illustration, the second-order corrections to the ground-state energy of some atoms and diatomic molecules with closed electron shells have been calculated.