fork(1) download
  1. use v5.10;
  2.  
  3. my $str = 'variable_name, VARIABLE_NAME, _var_x_short, __variable__name___';
  4.  
  5. ### solution 1
  6. $_ = $str;
  7.  
  8. $_ = lc;
  9. s/_(\w)/\U$1/g;
  10.  
  11. say;
  12.  
  13. ### solution 2: multi/leading underscore fix
  14. $_ = $str;
  15.  
  16. $_ = lc;
  17. s/(?<=[^\W_])_+([^\W_])|_+/\U$1/g;
  18.  
  19. say;
  20.  
  21. ### solution 3: without prior lc
  22. $_ = $str;
  23.  
  24. s/(?<=[^\W_])_+([^\W_])|([^\W_]+)|_+/\U$1\L$2/g;
  25.  
  26. say;
Success #stdin #stdout 0s 4728KB
stdin
Standard input is empty
stdout
variableName, variableName, VarXShort,  _variable_name__
variableName, variableName, varXShort,  variableName
variableName, variableName, varXShort,  variableName