my $userid = "rsennat"; # assume userid is set to a var my $string = "$str1,$str2"; # NB: using double quotes so that the $userid is interpolated # Single quotes would protect the literal string like \$userid my $tmp_file = "/tmp/$userid"; open(TMPFILE, ">> $tmp_file") || die "Can't write to '$tmp_file': $!\n"; print TMPFILE $string; close(TMPFILE);