I was writing this on a machine without Perl, thus the syntax error and no testing; I also tried to be extra safe with context in the do
. That scalar
is not necessary.
Sorry for the confusion, if there was any.
As for the OP's intent: it is hard to understand it. But the title question was "How to club different lines of program into one", so I tried to do the same thing the OP's code is doing, but in less lines.
And I don't have an excuse for not testing my open except that I usually use autodie.