#!/usr/bin/env perl #use v5.20; #use feature qw(signatures); #no warnings qw(experimental::signatures); use v5.36; use autodie; exit 1 if not @ARGV; sub read_file ($fh, $chunk_size=65536) { # Return the next chunk, including to the end of line. read($fh, my $chunk, $chunk_size); if (length($chunk) && substr($chunk, -1) ne "\n") { return $chunk if eof($fh); $chunk .= readline($fh); } return $chunk; } my $mul_pattern = 'mul\(\d{1,3},\d{1,3}\)'; my $filename = shift; my $count = 0; if (open(my $fh, '<', $filename)) { while (length(my $chunk = read_file($fh))) { $count += () = $chunk =~ m/$mul_pattern/g; } } print "Found $count matches.\n";