# replace all multiple whitespace characters from $string # \s represents a whitespace character (space, tab, newline etc) # + means 'one or more' $string =~ s/\s+/ /g;