in reply to weird behaviour of binmode

Before you fixed your typo, the second binmode in the second snippet was failing, so a second encoding layer wasn't being added, so you didn't double-encode.

With the typo fixed, you add two encoding layers, so you double-encode the second print, so you get garbage for the second print.

With typo fixed:

$ perl b1.pl 中文 "\x{0590}" does not map to cp936 at b1.pl line 8. "\x{0384}" does not map to cp936 at b1.pl line 8. \x{0590}\x{0384} $ perl b2.pl 中文 "\x{0590}" does not map to cp936 at b2.pl line 7. "\x{0384}" does not map to cp936 at b2.pl line 7. \x{0590}\x{0384}