in reply to Replace all occurrences but the last

substr($s, 0, rindex($s, ".")) =~ y/./_/;