use strict; use warnings; use autodie; my $input = 'D:/Some/Specific/Path/To/Input.CSV'; my $output = 'D:/Some/Specific/Path/To/Output.CSV'; open IN,$input; binmode(IN); open OUT,'>'.$output; my $count = 0; my @vk; # declare array to store all unique VK-codes my %seen; # declare hash to 'memorise' which VK has already been pushed while (my $line = ) { chomp $line; # good practice? next if $. < 2; # do not need first line my @fields = split ";" , $line; # define input-lines push (@vk,$fields[1]) unless $seen{$fields[1]}; # extract all and only unique VK-codes } close IN; # do not need this anymore for my $vk (@vk) { # we need to print each one if ($count != 10) { # we want 10 VK-codes per line -- works as intended print OUT $vk.';'; ++ $count; } else { print OUT "\n"; $count = 0; } } close OUT; exit 0;