Search the directory tree starting from the root directory (/) up to a maximum depth of 4 levels, for files with the extensions .jpg, .gif, .py, or .pl, and then search each of those files for the string "foo".
find / -maxdepth 4 -regex ".*\.\(jpg\|gif\|py\|pl\)" | xargs grep -n "foo"