As stated in other answers, the shell does not replace the variables inside single quotes, so the second version executes the literal operator Perl s{(?i)$file_ref}{$file_ref}g for each line in each file.
As you said in a comment, if $ is the end-of-line metacharacter, $file_ref never match anything. $ matches before a new line at the end of a line, so the next character must be a new line. Therefore, Perl does not interpret $ as a metacharacter; he interprets it as the beginning of an interpolation variable.
In Perl, the variable $file_ref is undef , which when interpolated is treated as an empty string. So you really do s{(?i)}{}g , which says, to replace the empty string with the empty string and do this for all occurrences case sensitive. Well, there is an empty line between each pair of characters, plus one at the beginning and at the end of each line. Perl finds each and replaces it with an empty string. It is not-op, but it is expensive, therefore, 3 hours work time.
You must be mistaken in the fact that both versions make the same changes. As I just explained, the single-quoted version is just an expensive option, no; it does not make any changes to the contents of the file (it simply creates a new copy of each file). The files on which you ran it should have been converted to lowercase.
source share