while (( $fig, $img) = each(%images)) { grep{$fig} "$html_dir/$FigFile/$DirFile"; s/$fig/"$fig<\/a>"/g; %images = (); }