in reply to Binary Data File

Minor note first: why did you put $data_file in quotes? There is no reason to do so except in a few very special cases. Otherwise, it's useless extra effort.

Now if I understood your specification correctly, you want this:

#!/usr/bin/perl -w use strict; my $data_file = "record"; open(FILE, "<", $data_file) or die $!; binmode(FILE); my $file_len = -s FILE; while($file_len > tell FILE) { read FILE, my $fixed, 8; my ($date, $rec_len) = unpack "L2", $fixed; read FILE, my $empl_info, $rec_len; # ... processing here } close FILE;
The key is the second read, which uses the just decoded length to determine how much to read. Instead of L2, you may need another format; see perldoc -f unpack and perldoc -f pack. (See perldoc -f -X and perldoc -f tell if you don't see just how that loop terminates.)

Makeshifts last the longest.