  Let $ f$ be a real-analytic function germ whose critical locus contains a
given real-analytic set $ X $, and let $ Y $ be a germ of closed subset of $
\mathbb{R}^n $ at the origin. We study the stability of $ f $ under
perturbations $ u $ that are flat on $ Y $ and that belong to a given
Denjoy-Carleman non-quasianalytic class. We obtain a condition ensuring that $
f+u=f\circ\Phi $ where $ \Phi $ is a germ of diffeomorphism whose components
belong to a (generally larger) Denjoy-Carleman class. Roughly speaking, this
condition involves a \L ojasiewicz-type separation property between $ Y $ and
the complex zeros of a certain ideal associated with $ f $ and $ X $. The
relationship between the Denjoy-Carleman classes of $ u$ and $ \Phi $ is
controlled precisely by the inequality. This result extends, and simplifies,
former work of the author on germs with isolated critical points.
