You split your $target, count each character and store it in a hash;
You split your $word into an array, loop through each letter;
For each letter in the array, you go to the hash and decrement the count by 1. If you encounter any letter that has no count in that hash or its count in the hash is zero, the process is terminated right the way and the answer is "not ok".