Challenge 2: Count and Print with -ne — Possible Solution ==================================================================== perl -ne '$c++ if /WARN/; END { print "$c\n" }' app.log WHY THIS WORKS AS AN ANSWER ------------------------------ -ne wraps the code in this chapter's own implicit while (<>) loop, running once per line of app.log with no automatic printing (that's what distinguishes -n from -p) — appropriate here since the goal is a single final count, not a transformed copy of every line. $c++ if /WARN/ reuses a bare regex match against $_ (the loop's default variable, holding the current line) — Course 1, Chapter 6's own pattern-matching-with-no-explicit-variable idiom — incrementing $c only on lines that actually contain "WARN". END { print "$c\n" } is this chapter's own END block, which runs exactly once after every line has been processed rather than once per line — the correct place to print a final summary value rather than printing it (and getting it wrong) inside the per-line loop itself. If app.log contains no lines matching /WARN/ at all, $c is never incremented and remains undef; printing "$c\n" in that case prints an empty line (with a "use of uninitialized value" warning under use warnings) rather than 0 — worth being aware of, though not relevant for a file that does contain matches.