Almost degenerate perturbation theory