Something like this might do it: :0fwH * ^TOlistaddress * !^Subject:[ ]*spookinfo:.* * ^Subject:[ ]*\/.* | formail -I "Subject: SpookInfo: $MATCH"