  A now classical result in the theory of variable Lebesgue spaces due to
Lerner [A. K. Lerner, On modular inequalities in variable $L^p$ spaces, Archiv
der Math. 85 (2005), no. 6, 538-543] is that a modular inequality for the
Hardy-Littlewood maximal function in $L^{p(\cdot)}(\mathbb{R}^n)$ holds if and
only if the exponent is constant. We generalize this result and give a new and
simpler proof. We then find necessary and sufficient conditions for the
validity of the weaker modular inequality \[ \int_\Omega Mf(x)^{p(x)}\,dx \
\leq c_1 \int_\Omega |f(x)|^{q(x)}\,dx + c_2, \] where $c_1,\,c_2$ are
non-negative constants and $\Omega$ is any measurable subset of $\mathbb{R}^n$.
As a corollary we get sufficient conditions for the modular inequality \[
\int_\Omega |Tf(x)|^{p(x)}\,dx \ \leq c_1 \int_\Omega |f(x)|^{q(x)}\,dx + c_2,
\] where $T$ is any operator that is bounded on $L^p(\Omega)$, $1<p<\infty$.
