A simpler / more readable soln would be to use substr(0):
$value = substr($string, $offset, $count);
eg
$value = substr($string, 0, 5);
you could even compare the 2 strings in one hit:
Code:
if( substr($string1, 0, 5) eq substr($string2, 0, 5) )
{
do something...
}