Increase Performance

I have written a code using AWK & sed to compare two files.
The structure of the files is like this"

Format is this:
<bit code> <file code> <string>
Follwoed by any numbers of properties lines whic start with a "space"

10101010101111101 XX abcd a
AS sasa
BS kkk
1110000101010110 XX abde s
BS jsa
0110000101010100 XX acde sa
1010000101010110 XX adfe ma
AS asas
BS sasa
CS asa

.............................................
.....................................

Containing millions of records like this
Note

  1. A new record starts wherever a new line is starting with 1/0
  2. Anyline starting with space is properties associated with the last
    1/0 record
  3. The number of records depicted in above file is 4

I am taking one string at a time (abcd a) and start looking for it in other file, in the string column for 2nd file, until i find that. If that string is found then we compare bit code, file code and properties for that string.
(Although both files are sorted yet some records in either of file may be missing so i can't do line by line comparison)

The behaviour of program is fine but it's taking a lot of time as it is searching through a big file.
So please help me in suggesting how to enhance this file comparison

Thanks
Sandeep

Try doing this in pearl instead, the speed will increase very mutch.