$ perl -wle 'print scalar (()=/\S+/g) for "a b c", " a b c", "a b c ", " a b c "' 3 3 3 3 $ _