my $str = "abc def 123 456" ; $str =~ s/(?:\s)\w/_/g ; print $str ;