use strict; my $length=0; while(<>){ chomp; # did you want to get rid of newlines? otherwise use tr/// $length += length; } print $length, "\n";