#!/usr/bin/perl use v5.35.0; my $sum = 0; my $enabled = 1; while (<>) { s/ (do)\(\) | (don't)\(\) | mul\((\d{1,3}),(\d{1,3})\) / if ($1) {$enabled = 1} elsif ($2) {$enabled = 0} elsif ($enabled) {$sum += $3 * $4} /xge; } say $sum;