in reply to parse a string

A couple people have suggested a regular expression matching non-whitespace at the end of the string, which is a good solution. You can also take advantage of the greediness of the star operator, like this:
$text =~ /.*\s/; $index = $+[0]-1; # $index now contains the offset of the last space char