in reply to Re^2: removing redundantwhitespace
in thread removing redundantwhitespace

It seems to me that you want a run of whitespace that includes a newline to become a single newline, and a run of spaces to become a single space. It's not clear to me what you want to happen to a run of whitespace that includes a tab, but no newline; let's suppose that you want that to collapse to just a space, too. If your entire string (including newlines) is in the scalar $string, then
$string =~ s/\s*\n\s*/\n/g; $string =~ s/\s+/ /g;
should do it. This will not destroy leading and trailing whitespace; for that, you should use ikegami's solution, or read again the links in Re: removing redundantwhitespace.