use Encode; my $string = decode_utf8($bytes); deal_with_malformed_utf8() unless defined $string # or utf8::decode($string = $bytes) # of course, you can just or deal_with_malformed_utf8();# use one variable, and not # keep the raw bytes.