in reply to Removing underscores.

you could do $txt= join ('', ($txt =~ /(.*)_(\..*)/)) || $txt;