'__xxx__' =~ m/ \b # word boundary, matches begin of the string _+ # matches a couple of '_' because greedy (\w+) # matches the rest(greedy) but must do backtrack for whole regexp match _+ # after one backtrack matches last '_' \b /x;