$ perl -nE "/: / and $c += (split/: /)[0]; if( eof(ARGV) ){ say qq[SUM.$ARGV =$c]; $c=0 }" tmp_* syntax error at -e line 1, near "+=" syntax error at -e line 1, near "; =" Execution of -e aborted due to compilation errors. #### $ c=10 $ echo c c $ echo $c 10 $ echo "The total is: $c" The total is: 10 $ echo 'The total is: $c' The total is: $c