my $raw = do { open(my $fh, '<', $file) or die("Could not read file: $!\n"); binmode $fh; local $/; \<$fh> }; $$raw =~ ...; ## etc.