The FAQ entry at:
http://www.perlmeme.org/faqs/regexp/assign_in_one.html
is incompete.
The first code sample does not declare $string1 and
$string2
as lexical variables, and the solution code should be a
complete
working example. Perhaps something like:
#!/usr/bin/perl
use strict;
use warnings;
my $string1;
my $string2 = ' some text';
($string1 = $string2) =~ s/\s+//g;
print "$string1\n";