while (<$in>) { if ($index{$.}){ s/foo/bar/g; } print $tmp $_; }