How to Silent the Warning of "Parsing of undecoded UTF-8 will give garbage when decoding entities at ..."

When we use the LWP to parse a page that is UTF-8 encoded, we get a warning of "Parsing of undecoded UTF-8 will give garbage when decoding entities at /usr/share/perl5/LWP/Protocol.pm line 114". This is documented in HTML::Parser's manual.

A simple way to get around this is to silent the warning like this:

BEGIN {
  $SIG{'__WARN__'} =
    sub {
      warn $_[0]
        if index($_[0], 'Parsing of undecoded UTF-8 will give garbage') < 0;
    };
}

This sets a __WARN__ handler to output the warning only if the warning has nothing to do with "Parsing of undecoded UTF-8 will give garbage". You can check "perldoc -f warn" and "man perlvar" to get more information on this.