$ cat script.pl print("set var=val\n"); print("set foo=bar\n"); print("cd /some/path\n"); $ script.pl > temp_file && source temp_file && rm temp_file