my ($x, $y, $z, $n, $len) = ... # fill in these parameters my $format = "V$x n$y n C$z ".("Z$len" x $n); my $recsize = 4*$x + 2*$y + 2 + $z + ($n*$len); open B, '<', 'binary_file.bin' or die ...; while (read(B, $buf, $recsize) == $recsize) { my @values = unpack($format, $buf); my @x = splice(@values, 0, $x); # snip off the 4-byte ints my @y = splice(@values, 0, $y); # the 2-byte ints my $bits = splice(@values, 0, 1); my @z = splice(@values, 0, $z); # the 1-byte ints # @values now contain just the null-terminated strings # manually fix up signed vs. unsigned shorts in @y: $y[1] -= 65536 if ($y[1] > 32767); # repeat for each signed valued ...process the record... }