use strict; use warnings; my @CPU_SPLIT = split /\s+/, $CPU; # split the string on one or more spaces # ~ s\ //g; # this line does not make any sense to me, commented out. my $result = join ' ', @CPU_SPLIT; # join can operate directly on an array, no need to list the indices