in reply to Multiple STDIN sources
Your code can work as-is if you can change the way you call the script. Instead of a shell redirect (myprogram.pl < myfile.txt), leave out the < and let the diamond do the work (leaving STDIN alone):
myprogram.pl myfile.txt
Instead of a shell pipeline (some_process | some_filter | myprogram.pl), let the magical open (inside the diamond) do the work:
myprogram.pl 'some_process | some_filter |'
BTW, for efficiency, you might want to slurp <> instead of repeatedly concatenating lines. (Reallocation of strings and all that.... Does anyone have a link to a quasi-official explanation of why it's more efficient?)
--
LP^>
|
|---|