Even if this is a
properly trimmed down example, I feel smell of XY problem here. What is the point of cyclying until you find a specific name and then printing it, if you know it in the first place?!?
You may try
-e "$img_dir/$_" and print for $img_name;
instead.