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