$? is assigned a value in the background on the line @output = `$cmd`;, independent of what you do. The value itself depends on the status code returned from (I presume) iwodstart.

If you have multiple commands in $cmd or any i/o redirects (which you do), then the child process is actually a shell around your command set, and the return value in $? is the returned status code from the shell.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.