my @arr; # no need to initialize (and in any case, "= ''" makes little sense) my @hdr; open( F, "x.txt" ) or die $!; while () { chomp; my @flds = split /,/; push @array, join( ' ', @flds ); push @hdr, $flds[1]; } print join( '/', @hdr ), "\n"; print join( "\n", @array ), "\n";