my $untrusted = <>; # (or whatever you use to fetch it) my $test_utf8; eval "\$test_utf8 = decode( 'utf8', \$untrusted, Encode::FB_CROAK )"; if ( $@ ) { warn "Input data is not valid utf8: $@"; # take other appropriate action(s)... }