You mean just the space character? Not for any whitespace?
To check if a string contains only space characters, use
This sets $string to "Default" if $string consists of 0 or more space characters, and only space characters; if $string is " a " or something such, the regular expression won't match.my $string = " "; $string = "Default" if $string =~ /^ *$/;
If you're looking to match strings that consist only of whitespace (no non-whitespace characters), use:
\s matches whitespace, so this does the same as the last regex, but matches any whitespace (not just space characters).my $string = " \t \n "; $string = "Default" if $string =~ /^\s*$/;