use constant NAND_PAGE_SIZE => 16384; # or whatever... { open IMAGE, '<', $image_file_name or die "$image_file_name: $!"; local $/ = \NAND_PAGE_SIZE; while () { my $ppn = (tell IMAGE) / NAND_PAGE_SIZE; my $lpn = get_LPN($_); $PPN[$ppn] = { LPN => $lpn, XPPN => [ get_XPPNs($_) ] }; push @{$LPN[$lpn]}, $ppn; } close IMAGE; }