in reply to Initialize variable in BEGIN

Using -n just complicates things for nothing.

With -n:

#!/usr/bin/perl -n use strict; use warnings; our $total; BEGIN { $total = 0; } $total += $_; END { print $total, "\n"; }

Without -n:

#!/usr/bin/perl use strict; use warnings; my $total = 0; while ( <> ) { $total += $_; } print $total, "\n";

One is clearly a million times better.