PHP cli script for some simple pattern matching