So why don't you write your R script manually and just shell out to rcmd.exe with Perl? Typically I read data from a db with Perl/DBI, write it to a file, dynamically write an R script, shell to R (which opens the file, analyzes it, writes results to text), Perl validates the results, parses file, loads analyzed data back to DB. All is good in the world.