You're almost there; you are simply confused about operator priority. The code you want to use:
(my $hello_nospaces = $hello) =~ s/\s//g;
First, this sets the $hello variable to the value of the $hello_nospaces variable. Then it performs a lookup operation on $hello_nospaces , as if you said
my $hello_nospaces = $hello; $hello_nospaces =~ s/\s//g;
Since the bind operator =~ takes precedence over the assignment operator = , the way you wrote it
my $hello_nospaces = $hello =~ s/\s//g;
first performs the substitution on $hello , and then assigns the result of the substitution operation (which in this case is 1) to the variable $hello_nospaces .
mob
source share