in reply to A Better Way to Find the Position of the Last Non-Whitespace Character in the Last Element of an Array.

It is also possible to take advantage of the @LAST_MATCH_START (in English,  @- in Perlish) array (see perlvar) associated with the capture group variables $1, $2, etc.
>perl -wMstrict -le "$ARGV[$#ARGV] =~ m{ (\S) \s* \z }xms; my ($lastchr, $lastpos) = defined $1 ? ($1, $-[1]) : ('absent', -1); print '----- output -----'; print qq{last non-ws char is '$lastchr' at index $lastpos}; " "Message Line 1" "Message Line 2" "Message Line 3" "Prompt: " ----- output ----- last non-ws char is ':' at index 6
Update: Changed link to use English version of  @- to avoid rendering problems.
  • Comment on Re: A Better Way to Find the Position of the Last Non-Whitespace Character in the Last Element of an Array.
  • Select or Download Code