in reply to detect incorrect character encoding

You could be using a signal handler:
{ local $SIG{__WARN__} = sub { die "$filename is invalid utf8!\n" }; eval { .. }; }