use IO::File; print "Content-type: text/html\n\n"; print "Go..\n"; my $fh = IO::File->new_tmpfile(); if (defined $fh) { # Do something with the tmpfile print "Defined: $fh\n"; } else { # Do something in memory print "Not defined\n"; }