#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/file.csv'; open my $fh, '<', $file or die $!; while( my $line = <$fh> ){ my ($id, @array) = split /;/, $line; print $id, ";", $_,"\n" for grep{ defined }@array; } close $fh;