⭐ in reply to How do I remove whitespace at the beginning or end of my string?
Use substitution along with the special characters ^ and $ which match the beginning and end of strings respectively along with \s which matches whitespace;
$string=~s/^\s+//; $string=~s/\s+$//;
Edited by davido: Removed useless use of /g modifier.
|
---|
In Section
Seekers of Perl Wisdom