in reply to perl substitution difficulty

Your regex reads like this "find 1 or up to 6 whitespaces in a row, and substitute them by a comma".

What you want to do looks like this: substr($_, 0, 6) =~ s/\s/,/g;