#!/usr/local/bin/perl use strict; use warnings; open my $fh, '<', 'binary.file' or die "File not found: $!"; binmode($fh); my ($xdr, $buffer, $length) = ""; # read until end of file ... while (read ($fh, $buffer, 2) != 0) { # if file does not start with eye catcher skip until you find one next unless ((unpack 'H*', $buffer) eq "3d3d"); # append the eyecatcher to xdr variable $xdr .= $buffer; # read next two bytes which is length of the record read ($fh, $buffer, 2); # convert the binary length to decimal for use in read function my $length = unpack('s',pack 's', hex(unpack 'H*', $buffer)); # append the length to xdr variable $xdr .= $buffer; # read the binary stream till the length of record - 4 bytes read ($fh, $buffer, $length-4); # append the entire xdr $xdr .= $buffer; #send to parsing subroutine for parsing $xdr = ""; }