use v5.10;
my $str = 'variable_name, VARIABLE_NAME, _var_x_short, __variable__name___';
### solution 1
$_ = $str;
s/_(\w)/\U$1/g;
say;
### solution 2: multi/leading underscore fix
$_ = $str;
s/(?<=[^\W_])_+([^\W_])|_+/\U$1/g;
say;
### solution 3: without prior lc
$_ = $str;
s/(?<=[^\W_])_+([^\W_])|([^\W_]+)|_+/\U$1\L$2/g;
say;
dXNlIHY1LjEwOwoKbXkgJHN0ciA9ICd2YXJpYWJsZV9uYW1lLCBWQVJJQUJMRV9OQU1FLCBfdmFyX3hfc2hvcnQsICBfX3ZhcmlhYmxlX19uYW1lX19fJzsKCiMjIyBzb2x1dGlvbiAxCiRfID0gJHN0cjsKCiRfID0gbGM7CnMvXyhcdykvXFUkMS9nOwoKc2F5OwoKIyMjIHNvbHV0aW9uIDI6IG11bHRpL2xlYWRpbmcgdW5kZXJzY29yZSBmaXgKJF8gPSAkc3RyOwoKJF8gPSBsYzsKcy8oPzw9W15cV19dKV8rKFteXFdfXSl8XysvXFUkMS9nOwoKc2F5OwoKIyMjIHNvbHV0aW9uIDM6IHdpdGhvdXQgcHJpb3IgbGMKJF8gPSAkc3RyOwoKcy8oPzw9W15cV19dKV8rKFteXFdfXSl8KFteXFdfXSspfF8rL1xVJDFcTCQyL2c7CgpzYXk7
variableName, variableName, VarXShort, _variable_name__
variableName, variableName, varXShort, variableName
variableName, variableName, varXShort, variableName