You might want to look at "Wicked Cool Perl Scripts" published by (I believe) No Starch Press. I believe they have a script that might get you closer to what you're after. There's a script to monitor comic strip pages that may lead you in the direction what you're after.
Revolution. Today, 3 O'Clock. Meet behind the monkey bars.
I would love to change the world, but they won't give me the source code