in reply to Substr versus Regexp

Perl regular expressions are highly optimized. so people often write something like /^(...)/

however your particular example should be written other way. Looks like youre recently from C world... Welcome to perl! youll write shorter code soon...

addition using index function should boost speed and shorten your code simultaneously, see perldoc -f index

Best regards,
Courage, the Cowardly Dog