By default, there is a fundamental asymmetry in Perl's unicode model: implicit upgrading from byte-strings to unicode-strings assumes that they were encoded in ISO 8859-1 (Latin-1), but unicode-strings are downgraded with UTF-8 encoding. This happens because the first 256 codepoints in Unicode happens to agree with Latin-1.

However, this silent upgrading can easily cause problems, if you happen to mix unicode strings with non-Latin1 data -- i.e. byte-strings encoded in UTF-8 or other encodings. The error will not manifest until the combined string is written to output, at which time it would be impossible to see where did the silent upgrading occur.

Most of the time, this warning occurs when a byte-string is concatenated with a unicode-string. There are a number of ways to solve it:

Most of the time, this warning occurs when a byte-string is concatenated with a unicode-string. There are a number of ways to solve it: (TBT)

Upgrade both sides to unicode-strings

If your program does not need compatibility for Perl 5.6 and earlier, the recommended approach is to apply appropriate IO disciplines, so all data in your program become unicode-strings. See encoding, open and "binmode" in perlfunc for how.

If your program does not need compatibility for Perl 5.6 and earlier, the recommended approach is to apply appropriate IO disciplines, so all data in your program become unicode-strings. See encoding, open and "binmode" in perlfunc for how. (TBT)

Downgrade both sides to byte-strings

The other way works too, especially if you are sure that all your data are under the same encoding, or if compatibility with older versions of Perl is desired.

The other way works too, especially if you are sure that all your data are under the same encoding, or if compatibility with older versions of Perl is desired. (TBT)

You may downgrade strings with Encode::encode and utf8::encode. See Encode and utf8 for details.

You may downgrade strings with Encode::encode and utf8::encode. See Encode and utf8 for details. (TBT)

Specify the encoding for implicit byte-string upgrading

If you are confident that all byte-strings will be in a specific encoding like UTF-8, and need not support older versions of Perl, use the encoding pragma:

If you are confident that all byte-strings will be in a specific encoding like UTF-8, and need not support older versions of Perl, use the encoding pragma: (TBT)

use encoding 'utf8';

Similarly, this will silence warnings from this module, and preserve the default behaviour:

Similarly, this will silence warnings from this module, and preserve the default behaviour: (TBT)

use encoding 'iso-8859-1';

However, note that use encoding actually had three distinct effects:

However, note that use encoding actually had three distinct effects: (TBT)