a <- c("I need             only                <5                         white-spaces   removed")
gsub("(?<=\\S)\\s{1,4}(?=\\S)", "", a, perl=TRUE)