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; while (my $line = ) { chomp $line; # good practice? next if $. < 2; # do not need first line my @fields = split ";" , $line; # define input-lines my @vk = $fields[1]; # extract all VK-codes my %seen; # declare hash to 'memorise' which VK has already been pushed my @uniq; # declare array to store unique values for my $vk (@vk) { # need to 'check' all VK-codes in @vk push (@uniq, $vk) unless $seen{$vk}; # only push VK-codes that are not yet pushed for my $uvk (@uniq) { # uvk = unique VK if ($count != 10) { # we want 10 VK-codes per line -- works as intended print OUT $uvk.';'; ++ $count; } else { print OUT "\n"; $count = 0; } } } } close IN; close OUT; exit 0;