$ perl -wE 'my $str = "JA_PH"; $str =~ s/_/\s/; say $str' Unrecognized escape \s passed through at -e line 1. JAsPH $ perl -wE 'my $str = "JA_PH"; $str =~ s/_/ /; say $str' JA PH #### $ perl -wE 'my $str = "Some text with whitespace"; $str =~ s/\s /_/g; say $str' Some text with_whitespace $ perl -wE 'my $str = "Some text with whitespace"; $str =~ s/\s/_/g; say $str' Some_text_with__whitespace $ perl -wE 'my $str = "Some text with whitespace"; $str =~ s/\s+/_/g; say $str' Some_text_with_whitespace