in reply to Problem with (recursively?) searching flat file database

I guess you didn't post the complete program in here:
@results = grep( /^$line[3]/, @raw_data);
Where is the @line array coming from in this code?

Anyway, if the data file contains lines like:

1235 some text data 784783 some other data
You can do something like:
my $search_for = "text"; my $re = qr/^(\d+)\s+\Q$search_for\E/; open D,"data.txt" or die "Cant open file: $!"; while (<D>) { /$re/ or next; print "$1\n"; } close D;
to print all the numbers that correspond to the text "text". (and will not print records that have a number that happens to match your search query).

See also perlop and perlre.

-- Joost downtime n. The period during which a system is error-free and immune from user input.