c:\test>type readIndexedFile.pl #! perl -sw use strict; use Time::HiRes qw[ time ]; our $N //= 100; open INDEX, '<:raw', "$ARGV[ 0 ].idx" or die $!; my $len = -s( INDEX ); sysread INDEX, my( $idx ), $len; close INDEX; sub getRecordN { my( $fh, $n ) = @_; seek $fh, unpack( 'N', substr $idx, ($n-1) * 4, 4 ), 0; return scalar <$fh>; } open DAT, '<', $ARGV[ 0 ] or die $!; for my $line ( 1 .. ( length( $idx ) / 4 ) - 1 ) { print "Expecting $line; got: ", getRecordN( *DAT, $line ); } c:\test>readIndexedFile junk.dat Expecting 1; got: Line 0000000001 Expecting 2; got: Line 0000000002 Expecting 3; got: Line 0000000003 Expecting 4; got: Line 0000000004 Expecting 5; got: Line 0000000005 Expecting 6; got: Line 0000000006 Expecting 7; got: Line 0000000007 Expecting 8; got: Line 0000000008 Expecting 9; got: Line 0000000009 Expecting 10; got: Line 0000000010 Expecting 11; got: Line 0000000011 Expecting 12; got: Line 0000000012 Expecting 13; got: Line 0000000013 Expecting 14; got: Line 0000000014 Expecting 15; got: Line 0000000015 Expecting 16; got: Line 0000000016 Expecting 17; got: Line 0000000017 Expecting 18; got: Line 0000000018 Expecting 19; got: Line 0000000019 Expecting 20; got: Line 0000000020 Expecting 21; got: Line 0000000021 Expecting 22; got: Line 0000000022 Expecting 23; got: Line 0000000023 Expecting 24; got: Line 0000000024 Expecting 25; got: Line 0000000025