use Unicode::UCD qw/charscript/; # ... my %scripts; $scripts{charscript ord substr $_, 0, 1}++ foreach (@lines);