use strict; use warnings; open (NEW, ">", "OUTPUT_COMMA.txt" ) or die "could not open:$!"; open (FILE, "<", "INPUT.txt") or die "could not open:$!"; while (my $line = ) { $line =~s/\s{3} +/,/g; print NEW $line; } close (FILE); close (NEW)