One example is my "rep" script, which does just this using Perl:
http://rrt.sc3d.org/Software/Miscellaneous%20utilities(I'm just copying this to the list so others can see I've replied; probably better keep replies to this post off-list unless they actually involve grep!)
