in reply to changing a portion of a line leaving its formatting intact

Not a direct answer to your question, but consult perldoc perlrun for the -a flag which you've inadvertently recreated.