use Encode; ... # load the string into $_, then: my $test; eval "\$test = decode( 'utf8', \$_, Encode::FB_CROAK )"; if ( $@ ) { # Encode would fail/die if $_ was not a valid utf8 string }