A question about Measurable function Let $f$ be a real-valued Lebesgue measurable function on $\mathbb{R}$. Prove that there exist Borel measurable functions $g$ and $h$ such that $g(x)=h(x)$ almost everywhere and $g(x)\le f(x) \le h(x)$ for every $x \in \mathbb R$.
I know that $f$ is measurable since there exists a sequence of simple function that converges to $f$. I have no further idea how to tackle this problem.
 A: It seems that this is in fact not possible: there exists a measurable function $f:\mathbb R\to\mathbb R$ for which one cannot find any Borel function $h:\mathbb R\to\mathbb R$ such that $f\leq h$ everywhere.
Here is a (hopefully correct) example. Since my previous answer was wrong, I would be glad to know if this one is OK...
Take a perfect set $K\subseteq\mathbb R$ with Lebesgue measure $0$. The family of all perfect subsets of $K$ has the cardinality of the continuum; so (using the axiom of choice), one can enumerate the perfect subsets of $K$ as $(L_\alpha)_{\alpha<\mathfrak c}$. Then, one can define by transfinite induction a family $(C_\alpha)_{\alpha<\mathfrak c}$ of countable (infinite) sets such that $C_\alpha\subseteq L_\alpha$ and $C_\alpha\bigcap \left(\bigcup_{\beta<\alpha} C_\beta\right)=\emptyset$ for all $\alpha<\mathfrak c$. Indeed, if the $C_\beta$ have been found for all $\beta<\alpha$, then the set $Z_\alpha:=\bigcup_{\beta<\alpha} C_\beta$ has cardinality less than $\mathfrak c$, so $L_\alpha\setminus Z_\alpha$ is infinite because $L_\alpha$ has cardinality $\mathfrak c$, and hence $L_\alpha\setminus Z_\alpha$ contains a countable infinite set $C_\alpha$.
Now, enumerate each $C_\alpha$ as $C_\alpha=\{ x_{\alpha,n};\; n\in\mathbb N\}$, and define a function $f:\mathbb R\to\mathbb R$ as follows : $f(x_{\alpha,n}):=n$ for all $\alpha,n$, and $f(x)\equiv0$ outside $\bigcup_{\alpha<\mathfrak c} C_\alpha$. This is a measurable function because $f(x)\equiv 0$ outside $K$ (and hence almost everywhere). On the other hand, the function $f$ has the following property : it is not bouded above on any perfect subset of $K$.
Assume that one can find a Borel function $h:\mathbb R\to\mathbb R$ such that $f\leq h$. Since $h$ is real-valued, we have $K=\bigcup_{n\in\mathbb N} B_n$, where $B_n:=\{ x\in K;\;  h(x)\leq n\}$. Since $K$ is uncountable, at least one of the sets $B_n$ must be uncountable; and since $B_n$ is a Borel set (because $h$ is Borel), it must contain some perfect set $L$ (by a well known theorem). Then $h$ is bounded above on $L$, a contradiction since $h\geq f$ and $f$ is not bounded above on $L$.
A: Warning. What follows does not provide an answer to the question.
First, assume that $f$ is an indicator function, say $f=\mathbf 1_A$ where $A$ is a measurable. You can find Borel sets $B,C$ such that $B\subseteq A\subseteq C$ and $C\setminus B$ has measure $0$; then take $g:= \mathbf 1_B$ and $h:=\mathbf 1_C$.
Next, assume that $f$ is a simple function, say $f=\sum_{i=1}^N \alpha_i\mathbf 1_{A_i}$, where the sets $A_i$ are measurable and $\alpha_i\in\mathbb R$. By the first case, one can choose Borel functions $g_i$ and $h_i$ such that $g_i=h_i$ almost everywhere and $g_i\leq \mathbf 1_{A_i}\leq h_i$ if $\alpha_i\geq 0$, whereas $h_i\leq \mathbf 1_{A_i}\leq g_i$ if $\alpha_i<0$. Then take $g:=\sum_i\alpha_i g_i$ and $h:=\sum_i\alpha_i h_i$.
Finally, assume that $f$ is an arbitrary measurable function. One can find a sequence of simple measurable functions $(f_n)$ such that $f_n\to f$ everywhere. For each $n$, choose Borel functions $g_n$ and $h_n$ such that $g_n\leq f_n\leq h_n$ and $g_n=f_n=h_n$ almost everywhere. Now define $\widetilde g:=\limsup g_n$ and $\widetilde h_n:=\liminf h_n$. These are Borel extended real-valued functions, and $\widetilde g\leq f\leq\widetilde h$ because $g_n\leq f_n\leq h_n$ for all $n$ and $f_n\to f$. Moreover, we have $\widetilde g=f=\widetilde h$ almost everywhere because $g_n=f_n=h_n$ almost everywhere for each $n\in\mathbb N$ and $f_n\to f$. Now, set $E:=\{ \widetilde g=-\infty\}\cup\{\widetilde h=+\infty\}$, a Borel set of measure $0$ because $f$ is real-valued and $g=f=h$ a.e. Define $g:=\widetilde g$ on $\mathbb R\setminus E$ and $g:=0$ on $E$; and likewise $h:=\widetilde h$ on $\mathbb R\setminus E$ and $h:=0$ on $E$.
Unfortunately, this doesn't work since, as pointed out by @quartermind, one does not know that $g\leq f\leq h$ on $E$. 
