in reply to Re^3: search for a string and return previous relating string if found
in thread search for a string and return previous relating string if found

Just two nitpicks: glob splits its argument on whitespace, so $dir can't contain any whitespace - except if you do use File::Glob ':bsd_glob';, which I'd strongly recommend in this case. Also, filenames beginning with a dot will be ignored (which is probably fine but should be mentioned).