#!/usr/bin/env perl use 5.012; use warnings; my %cc; # map of country code to info array while (<>) { /^#/ and next; # skip comments my ($iso, $name, $cont) = (split /\t/)[0, 4, 8]; my $class = "c-\L$cont"; $cc{ lc $iso } = [ $name, $class ]; } for (values %cc) { for ($_->[2] //= $_->[0]) { s/,.*//; s/(?<=.)\(.*\)\s*//; s/ republic\b//gi; s/ islands?\b//gi; s/\bthe //g; s/ and / & /g and s/(?<=.)[a-z ]+//g; s/\bsaint /st /gi; s/South(?:ern)? /S-/g; s/North(?:ern)? /N-/g; s/New /n./g; s/(\S)(\S+)-/$1-/g; # strip most chars preceding dash s/(\S{4}[b-df-hj-np-tv-xz])((? countries.inc.pl