use warnings; use strict; my $infile="clients.txt"; open my $in, "<", $infile or die $!; open FH, ">" , "clients.csv" or die $!; print FH join ("," => qw(Name Phone E-mail)),$/; while (<$in>) { chomp; print FH $_, "\t"; print FH $/ if $. % 3 == 0; # note here }