in reply to Re^2: Is there a way to make these two regex lines cleaner?
in thread Is there a way to make these two regex lines cleaner?

I am using the use the Spreadsheet::Read module.

That's an important piece of information missing from the root node! I am guessing that your files are CSV files? Because opening any other file type (XLS, XLSX, etc.) with an '<:raw:encoding(UTF-8)' will likely corrupt those files, and ReadData($filename) should be preferred there. And for CSV files, Spreadsheet::Read uses Text::CSV or Text::CSV_XS under the hood, both of which have a detect_bom option when used directly - unfortunately I currently don't see a way to get Spreadsheet::Read to apply that option, so unless Tux has any hints, you could use one of those two CSV modules directly.

In any case, you may want to check your $filename to see if it's a CSV file first, before handing it off to the processing code appropriate for the file type.

Update: Regarding read $fh, my $string, -s $fh;, the idiomatic way to slurp a file in Perl is my $string = do { local $/; <$fh> }; (see $/). Other minor edits. And you need to check your open for errors, see "open" Best Practices.