use strict; use warnings; my $s = 'Intel(R) Xeon(R) CPU X5660 2.80GHz '; $s =~ s{ (\s)+ }{$1}gx; $s =~ s{ \s+ $ }{}x; print "\n>$s<\n";