| Home » Faqs » Regexp » Assign in one |
You want to do:
#!/usr/bin/perl
use strict;
use warnings;
$string1 = $string2;
$string1 =~ s/\s+//g;
in one line.
The most common and recommended solution is:
($string1 = $string2) =~ s/\s+//g;
which has the effect of making a copy of $string2 in $string1, and then
applying the substitution to $string1.
However another solution is:
s/\s+//g for $string1 = $string2;