For programming questions about reading a file fully in one operation rather than reading it one line at a time.
In Perl, slurp mode is activated by un-setting a special variable: $/ = undef;
after which, reading from a file handle will read the entire file rather than the default of just one line from it.
There is also a File::Slurp Perl module that offers similar functionality of reading the entire contents of a file through a read_file
method rather than messing around with magic variables.
Ansible has a similar concept with a built-in slurp module that fully reads files from remote nodes.