use File::Temp qw(tempdir); sub sa_t_init { my $tname = shift; $tname = untaint_var($tname); ... unless (-d "log") { mkdir ("log", 0755) or die ("Error creating log dir: $!"); } chmod (0755, "log"); # in case already exists with wrong permissions ... $workdir = tempdir("$tname.XXXXXX", DIR => "log"); # Simple version of untaint_var for internal use sub untaint_var { local($1); $_[0] =~ /^(.*)\z/s; return $1; }