my $rawstring = ...; # coming from a cgi param or whatever my $utfstring; eval { $utfstring = decode( "utf8", $rawstring, Encode::FB_CROAK ) } if ( $@ ) { # do something sensible given that $rawstring is invalid # (i.e. cannot be converted successfully to utf8) }