my $line='id, lang1_bez, lang1_url, lang2_bez, lang2_url, lang3_bez, lang3_url'; my @data=split_line($line); print join(', ',@$_)."\n" for(@data); sub split_line { my $line=shift; my @ret=(); my @elm=split(/,\s*/,$line); my $id=shift(@elm); while(my ($bez,$url)=splice(@elm,0,2)) { my ($lang)=$bez=~/^(.+?)_/; push(@ret,[$id,$lang,$bez,$url]); } return @ret; }