Also, if you need to read the output generated by the perl script, you might consider piping stdout with popen. Then whatever the script writes to stdout you can read in your program with fread as if it were from a file.

You have to create a buffer and copy the commands into it. C does not expand string variables like Perl does. You can do it with a std::string if you are in C++ or you have to allocate a char buffer (either on the stack or on the heap).