use File::Temp qw/tempfile/; my ($tfh,$tfn) = tempfile(UNLINK=>1); print $tfh <<'END_OF_SQL'; SET HEADING OFF; SELECT systimestamp || ' IP=' || sys_context('USERENV','IP_ADDRESS') FROM dual; EXIT END_OF_SQL close $tfh; # the filename is in $tfn # no "unlink" needed, that's automatic