以下のような関数を定義。
sub spacer { my $str = shift; my $east = qr/(?!\p{M})(?:\p{Han}|\p{Katakana}|\p{Hiragana})/; my $west = qr/(?!\p{M})(?:\p{Latin}|\p{Greek}|\p{Cyrillic})/; $str = decode 'utf8', $str; $str =~ s/($east)($west)/$1 $2/g; $str =~ s/($west)($east)/$1 $2/g; $str = encode 'utf8', $str; return $str; }
あとはwhile文の中とかでこの関数を呼び出す。