#!/usr/bin/perl use strict; use warnings; my %countries; open my $IN, '<:encoding(utf-8)', '1.csv' or die $!; while (<$IN>) { my @columns = split /;/; push @{ $countries{$columns[0]} }, $_; } for my $country (keys %countries) { open my $OUT, '>:encoding(utf-8)', "$country.csv" or die $!; for (@{ $countries{$country} }) { print {$OUT} $_; } close $OUT or die $!; }