1. $matlab_cmd_str = "$path_to_matlab -nodesktop -r my_script"; 2. open(RUN_MATLAB, "$matlab_cmd_str |") or die("Can't run $matlab_cmd_str: $!\n"); 3. while() { 4. print FH "$_"; 5. } 6. my $return_status = close(RUN_MATLAB); 7. unless($return_status) { print STDERR "There was a problem: $?\n"}