I think I will go with the regexp as several people suggested. Originally I didn't want to do that because I remembered a while back I did some benches on using regexp vs substr+index and the regexp was always slower. This code is to run in a mod_perl handler which handles a ton of requests and I was worried about it slowing everything down.
thanks