in reply to Substr versus Regexp
You can always replace substr with a regexp, but the regexp will generally be slower (though often not by much). That's because the additional flexibility of regular expressions requires that they be parsed and executed by a fairly elaborate regular expression engine, while substr basically indexes into an array and moves some characters around. Unless a regexp is much clearer or you can replace multiple calls to substr with a single regexp, you're usually better off using substr where possible.