PERLCN(1)

✨ NAME ✨

perlcn — 简体中文 Perl 指南 💅 (aka the Simplified Chinese Perl Guide, and it's giving iconic)

okay so this whole page is PERLCN(1), straight out of the Perl Programmers Reference Guide, and it's literally your bestie-approved starter pack for doing Chinese text in Perl without crying. 🎀


🌸 DESCRIPTION 🌸

欢迎来到 Perl 的天地! — welcome to the entire Perl universe, bestie, we're so happy you're here 🫶

Starting from version 5.8.0, Perl has full, proper Unicode (统一码) support — no cap. Which means it also plays nice with a whole bunch of non-Latin encodings, and CJK (中日韩 — Chinese, Japanese, Korean) is one of them. ✨ Unicode is this international standard that's genuinely trying to cover every character in the whole world: the Western world, the Eastern world, and absolutely everything in between (Greek, Syriac, Arabic, Hebrew, Indian, Amerindian, etc.). It also makes room for loads of different operating systems and platforms (like PC and Macintosh). 🌍

Perl itself operates in Unicode. Translation: Perl's internal string data can be represented in Unicode, and Perl's functions and operators (regex matching, hi 👋) can operate on Unicode too. On the way in and the way out — for data that's stored in pre-Unicode encodings — Perl hands you the Encode module, so you can read and write old-encoding-format data so easily. 💖

The Encode extension module supports these Simplified Chinese encodings ('gb2312' means 'euc-cn'):

  • euc-cn — the Unix extended character set, aka what everyone calls 国标码 (the Guobiao code)
  • gb2312-raw — the raw (low-bit) GB2312 character table
  • gb12345 — raw traditional-Chinese encoding as used in China
  • iso-ir-165 — GB2312 + GB6345 + GB8565 + newly added characters
  • cp936 — code page 936, which you can also point at by saying 'GBK' (the extended Guobiao code)
  • hz — 7-bit escape-style GB2312 encoding

For example, bestie — turning an EUC-CN file into Unicode is literally just:

perl -Mencoding=euc-cn,STDOUT,utf8 -pe1 < file.euc-cn > file.utf8

Perl also ships with "piconv", a character conversion tool written completely in Perl, used like this:

piconv -f euc-cn -t utf8 < file.euc-cn > file.utf8
piconv -f utf8 -t euc-cn < file.utf8 > file.euc-cn

Also also also — with the encoding module you can write character-based code so easily, like this:

#!/usr/bin/env perl
# 启动 euc-cn 字串解析; 标准输出入及标准错误都设为 euc-cn 编码
use encoding 'euc-cn', STDIN => 'euc-cn', STDOUT => 'euc-cn';
print length("骆驼");      #  2 (双引号表示字符)
print length('骆驼');      #  4 (单引号表示字节)
print index("谆谆教诲", "蛔唤"); # -1 (不包含此子字符串)
print index('谆谆教诲', '蛔唤'); #  1 (从第二个字节开始)

In that last example: the second byte of "谆" joins up with the first byte of "谆" to make the EUC-CN "蛔", and the second byte of "谆" joins with the first byte of "教" to make "唤". And that, my love, is exactly how the classic EUC-CN matching headache gets solved. 💅


🦋 额外的中文编码 (Extra Chinese encodings) 🦋

Need more Chinese encodings? Go download the Encode::HanExtra module off CPAN (https://www.cpan.org/). Right now it provides these encodings:

  • gb18030 — the extended Guobiao code, traditional Chinese included

Also, the Encode::HanConvert module gives you two encodings for simplified↔traditional conversion:

  • big5-simp — converts between Big5 traditional Chinese and Unicode simplified Chinese
  • gbk-trad — converts between GBK simplified Chinese and Unicode traditional Chinese

Wanna flip between GBK and Big5? Peep the b2g.pl and g2b.pl programs that come bundled with that module, or just do this inside your program:

use Encode::HanConvert;
$euc_cn = big5_to_gb($big5); # 从 Big5 转为 GBK
$big5 = gb_to_big5($euc_cn); # 从 GBK 转为 Big5

🌈 进一步的信息 (Further info) 🌈

Go read the enormous pile of documentation that ships with Perl (sadly it's all in English 😭) to learn more about Perl and about how to use Unicode. But honestly? The external resources are stacked:

💜 提供 Perl 资源的网址 (Sites that serve up Perl resources) 💜

🍓 学习 Perl 的网址 (Sites for learning Perl) 🍓

🧚 Perl 使用者集会 (Perl user groups) 🧚


👀 SEE ALSO 👀

Encode, Encode::CN, encoding, perluniintro, perlunicode


👑 AUTHORS 👑

  • Jarkko Hietaniemi <jhi@iki.fi>
  • Audrey Tang (唐凤) <audreyt@audreyt.org>
  • Sizhe Zhao <prc.zhao@outlook.com>

and that's the whole page, bestie!! this was perl v5.42.3, dated 2026-08-03, and yes, it's still PERLCN(1) — go forth and encode responsibly 🫶💖✨

📦 where this page comes from