use File::Temp qw(tempfile); my (undef,$file) = tempfile( DIR => '.' ); `echo "#!/bin/touch $file" > tmp.sh`; chmod 0755, 'tmp.sh'; system './tmp.sh';