Markov chain-based random text generator in Perl
The only thing that comes to mind is the way you open the file.

You could do this instead:

open(my $file, "&lt;", "$ARGV[0]") or die;
$data = do { local $/; &lt;$file&gt; };
close $file;


Which is a well known Perl idiom to read an entire file in one go.

For more info see these links

https://perlmaven.com/open-files-in-the-old-way

https://perlmaven.com/slurp

http://www.perlmonks.org/?node_id=20235