  In the context of $f(R)$ theories of gravity, we study the evolution of
scalar cosmological perturbations in the metric formalism. Using a completely
general procedure, we find the exact fourth-order differential equation for the
matter density perturbations in the longitudinal gauge. In the case of
sub-Hubble modes, the expression reduces to a second-order equation which is
compared with the standard (quasi-static) equation used in the literature. We
show that for general $f(R)$ functions the quasi-static approximation is not
justified. However, for those functions adequately describing the present phase
of accelerated expansion and satisfying local gravity tests, it provides a
correct description for the evolution of perturbations.
