TITLE: Is it possible to have the set $f^{-1}(\lbrace x \rbrace)$ perfect for every $x$?
QUESTION [12 upvotes]: There are examples of functions $f \colon [0,1] \longrightarrow [0,1]$ such that 
for any $\alpha $, $f^{-1}(\lbrace \alpha \rbrace)$ is uncountable. My favorite example is $$f(r) = \limsup_n \frac{a_1 + a_2 +\cdots + a_n}{n}$$ where $0.a_1a_2\cdots$ is the (non-terminated) binary expansion of $r$. 
Is there a continuous function $f \colon [0,1] \longrightarrow \Bbb{R}$ such that for any  $\alpha \in \Bbb{R}$, $f^{-1}(\lbrace \alpha \rbrace)$ is (non-empty) perfect ?

REPLY [6 votes]: Existence of such a function goes back to 1939:
J. Gillies, Note on a conjecture of Erdos, Quart. J. Math. Oxford 10, 1939, 151-154
Also, it can be shown that there is a residual set (a set whose complement is of first category) of continuous functions on $[0,1]$ such that for any $f$ in that set $f^{-1}(\lbrace \alpha \rbrace)$ is perfect except for countably many $\alpha$ and for each of the exceptional $\alpha 's$, $f^{-1}(\lbrace \alpha \rbrace)$ has the form $P\cup\lbrace t\rbrace$ where $P$ is perfect and $t$ is an isolated point of $f^{-1}(\lbrace \alpha \rbrace)$.