You'll need to use the unpack function on the data.
Check out: http://www.perlmonks.org/?node_id=224666
This should get you headed in the right direction: (assuming 32 bit)
#!/usr/bin/perl
use strict;
my $strBuf = "perl rocks";
my $packed = pack("I Z15", length($strBuf), $strBuf);
{
open(my $binFile, '>', "test.bin") || die("Error opening file\n");
binmode $binFile;
print $binFile $packed;
close $binFile;
}
open(my $binFile, '<', "test.bin") || die("Error opening file\n");
binmode $binFile;
my $buffer;
read($binFile, $buffer, 4); ## Read out unsigned int binary data
my $length = unpack("I", $buffer); ## Unpack the data
read($binFile, $buffer, $length); ## Read the length out as binary
my $string = unpack("Z$length", $buffer); ## Unpack the string data in buffer
print "Len: $length String: $string\n";
exit;