# prints "xxx_", instead of "xxx" print '__xxx__' =~ /\b_+(\w+)_+\b/ ? "$1\n" : "no match\n";