Forgive me if I don't see the problem here, but this sounds like a database join, not something you want to be loading into perl one row at a time. More like you want to do the join (is it SQL?) in the DB and capture the results if any. Approx:
SELECT * from lines, coords
WHERE x_pos >= start_x
AND x_pos <= end_x