To print the contents of a perl string that is being used as a buffer, you need to convert it to a printable form first. Use unpack for that.
For example to convert it to a string of hex digits:
print unpack('H*', $buffer),"\n";
Read perlpacktut to learn more.