I have many directories for different projects. Under some project directories, there are subdirectories named "matlab\_programs". In only subdirectories named matlab\_programs, I would like to replace the string 'red' with 'blue' in files ending with \*.m.

The following perl code will recursively replace the strings in all \*.m files, regardless of what subdirectories the files are in.

```
find . -name "*.m" | xargs perl -p -i -e "s/red/blue/g"

```

And to find the full paths of all directories called matlab\_programs,

```
find . -type d -name "matlab_programs"

```

How can I combine these so I only replace strings if the files are in a subdirectory called matlab\_programs?