You probably need to decode $img. See Encode, perluniintro.
In reply to Re: tr not working by Anonymous Monk in thread tr not working by ultranerds