http://www.perlmonks.org?node_id=808438


in reply to Append to file or create file depending on input filename.

Elegance is in the eye of the beholder of course, but how about:
open($filehandle, (($outfile =~ s/\A>//xms) ? '>>' : '>'), $outfile);
That is, if the substitution succeeds, it should return a true value (the number of things replaced, at least 1), and you get '>>' for your mode at the same time that you fix your outfile namae. Otherwise you get '>' for your mode. I wasn't sure about the evaluation happening in the right order, but I tested it and it seems to work. :)