use strict; open(my $fh, '<', 'some_binary_file') or die; binmode($fh); my $file_contents = do { local $/; <$fh> }; close($fh); $file_contents =~ /some-string/ and print "it matched\n";