Can't this be done using the -s switch on the $read fuction. It finds the first line that begins w/ that string and returns it.