I think the sipplest is to use an hash or arrays, in which the hash key will be the country (e.g. Norway) and the hash value an array of lines (in the xample, all the lines in which the last field if Norway).

Once you are done reading the log file, you iterate on the key of the hash and just output the libes stored in it.