$ echo AB | perl -lpe '$_=unpack"B*"' 0100000101000010 $ echo 0100000101000010 | perl -lpe '$_=pack"B*",$_' AB -e expressionevaluate the given expression asperlcode-p:sedmode. The expression is evaluated for each line of input, with the content of the line stored in the$_variable and printed after the evaluation of the expression.-l: even more likesed: instead of the full line, only the content of the line (that is, without the line delimiter) is in$_(and a newline is added back on output). Soperl -lpe codeworks likesed codeexcept that it'sperlcode as opposed tosedcode.unpack "B*"works on the$_variable by default and extracts its content as a bit string walking from the highest bit of the first byte to the lowest bit of the last byte.packdoes the reverse ofunpack. Seeperldoc -f packfor details.
With spaces:
$ echo AB | perl -lpe '$_=join " ", unpack"(B8)*"' 01000001 01000010 $ echo 01000001 01000010 | perl -lape '$_=pack"(B8)*",@F' AB (it assumes the input is in blocks of 8 bits (0-padded)).
With unpack "(B8)*", we extract 8 bits at a time, and we join the resulting strings with spaces with join " ".