#!/usr/bin/perl # the code is based on the one in http://www.kotnet.org/~skimo/cjk/cjk.html use Encode; sub octal { my ($t) = (@_); sprintf "\\%03o", ord($t); } sub convert { my ($t) = (@_); if ($t =~ /[\x80-\xFF]/) { Encode::from_to($t, "UTF-8", "UTF-16BE"); $t =~ s/(.)/${\octal($1)}/g; $t = "\\376\\377" . $t; } $t; } while (<>) { $_ =~ s/([^}]*}{)([^}]*)/$1${\convert($2)}/; print $_; }