Perl: Remove last non-white space character from string (most elegant solution?)

What is the most concise way to remove the last non-white space character from a string?
LVL 2
ZuZuPetalsAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
parparovConnect With a Mentor Commented:
$string =~ s/\S(\s*)$/$1/ if you need to retain the whitespace at the end
$string =~ s/\S\s*$// if you don't need to retain the whitespace at the end
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.