Use the length function to get the number of characters of a string. Special characters, such as new line (\n) and carriage return (\r) are also included in the length calculation.
Please notice that this function works on scalar variables, you can't use it to get the number of elements of an array or a hash.
$line = "perl test line\n";
print "\$line has " . length($line) . " lines\n";