title: How can I get Perl to detect bad UTF-8 sequences?
body: <p>I'm running Perl 5.10.0 and Postgres 8.4.3, and strings into a database, which is behind a <a href="http://search.cpan.org/dist/DBIx-Class" rel="nofollow noreferrer">DBIx::Class</a>.</p>
  
  <p>These strings should be in UTF-8, and therefore my database is running in UTF-8. Unfortunatly some of these strings are bad, containing malformed UTF-8, so when I run it I'm getting an exception</p>
  
  <p><code>DBI Exception: DBD::Pg::st execute failed: ERROR:  invalid byte sequence for encoding "UTF8": 0xb5</code></p>
  
  <p>I thought that I could simply ignore the invalid ones, and worry about the malformed UTF-8 later, so using this code, it should flag and ignore the bad titles.</p>
  
  <pre><code>if(not utf8::valid($title)){
     $title="Invalid UTF-8";
  }
  $data-&gt;title($title);
  $data-&gt;update();
  </code></pre>
  
  <p>However Perl seems to think that the strings are valid, but it still throws the exceptions.</p>
  
  <p>How can I get Perl to detect the bad UTF-8?</p>