perl -i.bk -lne 's/foo/bar/g if $.%2;print;' foo.txt