perl -p0e 's/\n^\s*$//mg' input.txt #### perl -ne 'print if /\S/' input.txt