first of all, why not using regexp for parsing the string:
if (/^\?/) {
next;
} elsif (/^\!/) {
rest of the code ;
}
It's much more clear, efficient and fast.
secondly, you have a problem with the double quotes inside your string, put single quote as outer quotes.
and third, after fixing the quotes problem it worked for me, I tried it myself.
Thanks.
Hotshot