perl -pe"BEGIN{$/=''} s/^\s+//; s/\s(?=\s)//g" test.txt > test.out