Long-range exchange and correlation effects, responsible for the failure of currently used approximate density functionals in describing van der Waals forces, are taken into account explicitly after a separation of the electron-electron interaction in the Hamiltonian into short- and long-range components. We propose a range-separated hybrid functional based on a local density approximation for the short-range exchange-correlation energy, combined with a long-range exact exchange energy. Long-range correlation effects are added by a second-order perturbational treatment. The resulting scheme is general and is particularly well-adapted to describe van der Waals complexes, like rare gas dimers.