in reply to opening files where name is a concatenation of variable

in addition to the problems and solutions discussed in other posts, i would like to suggest that the "tempname" variable you're concerned about having your script cluttered with is actually useful:

my $basedir = "results"; my $filename = $basedir . '/output/file.txt'; open my $outhandle, '>', $filename or die "opening $filename: $!"; ... print $outhandle $somestuff or die "writing $filename: $!"; ... close $outhandle or die "closing $filename: $!";