in reply to assign File Handles to Scalar Variables

The 2-arg open understands - to mean STDIN or STDOUT.

# XXX Unable to handle paths starting with a space or a # file named "-". The workaround is to prepend "./". my $file = @ARGV ? shift(@ARGV) : '-'; open(my $fh, "> $file") or die("Unable to open output file \"$file\": $!\n"); print $fh "this is a test\n";

Otherwise, you're stuck with an if statements. You could combine the two if statements into one, though.

Update: Added code.