=Katherine Richmond wrote:
> So I used this regular expression to replace 2 or more consecutive spaces with
> one space:
>
> $textline =~ s/\s{2,}/ /g;
=cut
## Maybe this can help you?
## Sample:
$_ = "first line
second line
third line
1234567890abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ";
## Filter:
s,[\040\011]+, ,g; ## reduce spaces or tabs to one space
## same as: s,[ ]+, ,g;
s,\n\040+,\n,g; ## erase leading blanks
s,\040+\n,\n,g; ## erase trailing blanks
## print:
print;
=Remarks:
\s means whitespace, which includes
space == chr(32) == \040
tab == chr(9) == \011
vertical tab == chr(11) == \013
line feed == chr(10) == \012
carriage return == chr(13) == \015 .
Because you want to leave line feeds as they are,
do not use \s , but invoce space and tab
expressively: \040\011.
Detlef