$text =~ /.*\s/; $index = $+[0]-1; # $index now contains the offset of the last space char