cat input | grep '^x' | sed 's/foo/bar/g'
sed '/^x/s/foo/bar/g' <input
sed -n '/^x/s/foo/bar/gp' <input