Perturbation theory for excited states of molecules