kenclark: Another approach to the problem is to say exactly what you want to do: trim all whitespace at the absolute beginning \A or at the absolute end \z of the string. This avoids any confusion with the various meanings of the ^ $ metacharacters. With a PBP-style substitution regex:
>perl -wMstrict -le "my $para = qq{\n\n \t \nsentence 1\nsentence 2\n\nsentence 3\n\n \t\n}; print qq{[[$para]]}; ;; $para =~ s{ \A \s+ | \s+ \z }{}xmsg; print qq{[[$para]]}; " [[ sentence 1 sentence 2 sentence 3 ]] [[sentence 1 sentence 2 sentence 3]]
In reply to Re^2: Trim blanks from the beginning and end of a multi-line string
by AnomalousMonk
in thread Trim blanks from the beginning and end of a multi-line string
by kenclark
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |