I would like to prove that $f:\mathbb R\longrightarrow \mathbb R$ is measurable $\iff$ $f^{-1}(B)$ is measurable for all Borel set $B$.
My definition of measurability if $f^{-1}((-\infty ,a))$ is measurable for all $a\in\mathbb R$. So the direction $\Leftarrow$ is obvious since $(-\infty ,a)$ is a Borel set. I have difficulity for the implication. The idea would be that every Borel set is a countable union and intersection of set of the form $(-\infty ,a)$ and $(a,+\infty )$ and thus it's measurable, but I'm not convinced by my argument.
Suppose that $f$ is measurable. Let $\mathcal{A}$ be the set of all parts $X$ of $\mathbb R$ such that $f^{-1}(X)$ is measurable. It is clear that it is a $\sigma$-algebra. Since $f$ is measurable, $\mathcal A$ contains all sets of the form $(-\infty,a)$. Since it is a $\sigma$-algebra, $\mathcal A$ must also contain the sets of the form $[a,+\infty)$. But then it contains all open intervals $(a,b)$, since$$(a,b)=\bigcup_{n\in\mathbb N}(-\infty,b)\cap\left[a+\frac1n,+\infty\right).$$Therefore, $\mathcal A$ contains all Borel sets.