use strict; # use warnings; my $file; my $dirname = $ARGV[0]; #warn "$dirname"; my @array; foreach my $file (<$dirname/*>) { next if -d $file; open( our $FILE, '<', $file ); binmode($FILE); #get filesize of file in process my $filesize = -s $file; #seek to text entry reference in file seek $FILE, 6, 0; read $FILE, my $buf, 2; #convert data my $abc = unpack('H*', $buf); my $offset = hex($abc); #use text entry reference to seek to actual text and print file/process info seek $FILE, $offset, 0; print "\n\n$file - size of file: $filesize - Text is at offset: $abc\n\n"; #loop thru file byte by byte doing processes depending on regex matches while (read($FILE, my $by, 1)){ #convert contents of byte to hex string my $byte = unpack('H*', $by); #if regex match is 00 return position in file of match, and #subtract offset to get total bytes read from middle of the file if ($byte =~ /00/){ my $pos = tell($FILE); #this subtraction will later be converted to a hex string "0xXX" my $decimal_value_pointer = $pos - $offset; my $pointer = sprintf("%X", $decimal_value_pointer); push (@array, qq($pointer\n)); #just prints correct pointer value in hex #print "pointer is: 0x$pointer\n\n"; next; # close $FILE; } #if $byte is ff then close file,which will jump back to the next file in the foreach loop if ($byte =~ /ff/){ close $FILE; } } } unlink ('temp'); open my $temp, '>>', "temp"; foreach my $lines(@array){ ++$_; print $temp "Pointer$_ - $lines"; } #### foreach my $line(@array){ foreach my file(0 .. 100 or however would be best){ open $file seek to static offset write $line from array to $file } }