open INPUT, "<./input.txt"; # assuming that's your input open OUTPUT, ">./output.csv"; # comma-separated-values output print OUTPUT "First column heading,Second column heading,Third column heading\n"; while () { my $first = s/(\d+)\.+//; my @others = split /\s\+/; print OUTPUT join(',' ($first, @others)).$/; }