I am just rigting a mere logic i am not writing a code. please adjust with me as am ina hurry to move out of my office.
Instead of the linenumber as has and elements in the array reverse this concept u will find a simple solution. Just build a hastable with ur elements as key and their line numbers as hash tabls. This would solve your problem.
Please let me know your comments on it.