Perl | length() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report length() function in Perl finds length (number of characters) of a given string, or $_ if not specified. Syntax:length(VAR) Parameter: VAR: String or a group of strings whose length is to be calculated Return: Returns the size of the string. Example 1: Perl #!/usr/bin/perl # String whose length is to be calculated $orignal_string = "Geeks for Geeks"; # Function to calculate length $string_len = length($orignal_string); # Printing the Length print "Length of String is: $string_len"; Output: Length of String is: 15 Example 2: perl #!/usr/bin/perl # String whose length is to be calculated $orignal_string = "123456 is Geeks Code"; # Function to calculate length $string_len = length($orignal_string); # Printing the Length print "Length of String is: $string_len"; Output: Length of String is: 20 Note : Scalar context on an array or hash is used if the corresponding size is to be determined. Comment More infoAdvertise with us Next Article MySQL LENGTH() Function C Code_Mech Follow Improve Article Tags : Perl Perl-String Perl-function Perl-String-Functions Similar Reads Perl | Useful String functions A string in Perl is a scalar variable and start with a ($) sign and it can contain alphabets, numbers, special characters. The string can consist of a single word, a group of words or a multi-line paragraph. The String is defined by the user within a single quote (â) or double quote (â). Perl provid 3 min read Perl | String functions (length, lc, uc, index, rindex) String in Perl is a sequence of character enclosed within some kinds of quotation marks. Perl string can contain UNICODE, ASCII and escape sequence characters. Perl provides the various function to manipulate the string like any other programming language. Some string functions of Perl are as follow 4 min read Perl | Math::BigInt->length() method Math::BigInt module in Perl provides objects that represent integers with arbitrary precision and overloaded arithmetical operators. length() method of Math::BigInt module is used to get the length of the given number i.e the count of digits in the given number. Syntax: Math::BigInt->length() Par 2 min read Perl | Getting the Number of Elements of an Array An array in Perl is a variable used to store an ordered list of scalar values. An array variable is preceded by an "at" (@) sign. The size of an array can be determined using the scalar context on the array which returns the number of elements in the array Example 1: Perl #!/usr/bin/perl # Initializ 2 min read MySQL LENGTH() Function MySQL LENGTH() function returns the length of a string in bytes. SyntaxThe MySQL LENGTH function syntax is: LENGTH(string) ParametersThe LENGTH function accepts only one parameter. string: A specified string whose length is to be counted.MySQL LENGTH() Function ExamplesLet's look at examples of the 1 min read Write your own len() in Python The method len() returns the number of elements in the list or length of the string depending upon the argument you are passing. How to implement without using len(): Approach: Take input and pass the string/list into a function which return its length.Initialize a count variable to 0, this count va 2 min read Like