http://www.perlmonks.org?node_id=1084035

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Oh monks most exalted and wise, a humble novice seeks to benefit from your vast knowledge of all things Perl.

I have a text file (UTF8-encoded) containing words, one per line, and I'm interested in finding out, for each word, how many characters are in it that do not appear in the English alphabet. So I whipped up a script to find out:

#!/usr/bin/perl use open IO => ':utf8'; while(<>) { chomp; ($nonenglish = $_) =~ s/[A-Za-z]//g; print length($nonenglish), " $nonenglish\n"; }

Alas, it isn't working; length appears to be counting bytes rather than characters! To wit:

$ perl nonenglish.pl æ 2 æ &#42853; 3 &#42853; &#173782; 4 &#173782; ^D $

I only occasionally use Perl, and I have no idea what I'm doing wrong. Enlighten me, kind monks, I beseech you!

My Perl is 5.14.2, BTW (and I cannot easily upgrade).