use strict; use warnings; my ($depth, $pos) = (0, 0); my ($depth2, $pos2, $aim) = (0, 0, 0); while (<>) { if (/forward (\d+)/) { $pos += $1; $pos2 += $1; $depth2 += $aim * $1; } elsif (/down (\d+)/) { $depth += $1; $aim += $1; } elsif (/up (\d+)/) { $depth -= $1; $aim -= $1; } } print $depth * $pos, "\n"; print $depth2 * $pos2, "\n";