use 5.008; my @cmd = ('cat', '/usr/share/dict/words'); die '@cmd must have more than one element' unless @cmd>1; open my $fh, '-|', @cmd or die $!; my $sum = 0; while (<$fh>) { chomp; $sum+=length; } close $fh or die $! ? $! : $?; print "$sum\n";