I know there’s many ways to do this, but I quite like this method for a batch file rename:
ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/bash
If you want to do a dry run first, then just omit the pipe to bash:
ls foo*.jpg | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2'