in reply to removing all whitespace but newlines

One way of doing so would be:
perl -wi -lpe 's/[[:space:]]+//g' file

Note the use of [:space:], the POSIX character class that includes all the whitespace characters. \s will not do, as that does not include the vertical tab character. Newlines won't be removed by the code above, as they are chopped off when reading a line, and added back on when printing it. It's the -l that will do this.

Abigail