use Regexp::Common qw/whitespace/; $foo =~ s/$RE{ws}{crop}//g;