# Search all files, then filter out the ones that don't end in '.pl' grep -Hnr mail *|grep '^[^:]*\.pl:' > results.txt # Find all .pl files and list the ones that contain 'mail' find /start_dir -name '*.pl' -exec grep -l mail {} \; > results.txt # Find all .pl files and show all the lines matching 'mail' as well as the file path find /start_dir -name '*.pl' -exec grep -n mail {} /dev/null \; > results.txt