OK, another suggestion 🙂
Wne you refer to an element in an array (or string), you should use [], not {}.
$outString=$outstring . ($inString{$i}$key{l});
should be
$outString=$outstring . ($inString[$i]$key[l]);
Also try to keep variable names the same case (though I am not sure it matters).
If this doesn't help you probably messed something up with , but I am not familiar with it 🙁