We know what code is "0", so that means that $temp is "0", so that means $tier is undef since it is never assigned a value. Undef stringifies to "", which is consitant with the results obtained. (You'll get a warning if warnings were used.) Maybe you need a default value for $tier?