use strict; use warnings; my $str = "Joe said hello"; print "\"$str\" --> \""; $str =~ s/\s(\s+)/" " . (" " x length ($1))/ge; print $str . "\"\n"; "Joe said hello" --> "Joe said   hello"