http://www.perlmonks.org?node_id=443392


in reply to Re: trim leading & trailing whitespace
in thread trim leading & trailing whitespace

\s matches newlines too, meaning that your pattern will remove empty lines, not just trim them. An alternative is

s/^[^\S\n]+//gm; s/[^\S\n]+$//gm;

ihb

See perltoc if you don't know which perldoc to read!