First, as PP notes, if your source file is encoded in UTF-8, you should use utf8;
so that Perl will know that and interpret any string literals in it correctly.
Second, make sure the text in the database is also correctly encoded. The details of this will depend on you database, but e.g. for MySQL, the best way is probably to make sure your text columns have the utf8
character set and the utf8_unicode_ci
collation (or the appropriate national collation scheme, if needed), and to include the mysql_enable_utf8
option when connecting to the database using DBI.
Third, you need to tell Perl that you want your I/O streams to be UTF-8 encoded, too. You can do this using binmode()
, as in:
binmode STDOUT, ':utf8';
Finally, you also need to tell the browser that you're sending it UTF-8 text. (I suspect this part is your actual problem, but if you do all the other steps too, you'll have achieved a fully Unicode-aware workflow.) You can do this by sending the HTTP header:
Content-Type: text/html; charset=UTF-8
and/or the equivalent HTML meta tag:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
or, in HTML5, simply:
<meta charset="utf-8">