Perl: Handle malformed UTF-8 strings with Encode::encode

Having the error message „Malformed UTF-8 character (fatal)“ in my log files, I tried to handle this properly without letting the process die nor throwing away the whole string.
Having some research on Google I came up with following solution:

See also:
http://perldoc.perl.org/Encode.html#Handling-Malformed-Data
http://www.perlmonks.org/?node_id=839519