$ perl -e " for my $l ( a..c ){ open $fh, '>', $l; print $fh qq[$l$_\n] for 1 .. 3; } " $ paste -d, a b c a1,b1,c1 a2,b2,c2 a3,b3,c3