Perl | unshift() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report unshift() function in Perl places the given list of elements at the beginning of an array. Thereby shifting all the values in the array by right. Multiple values can be unshift using this operation. This function returns the number of new elements in an array. Syntax: unshift(Array, List)Returns: Number of new elements in Array Example 1: Perl #!/usr/bin/perl # Initializing the array @x = ('Geeks', 'for', 'Geeks'); # Print the Initial array print "Original array: @x \n"; # Prints the number of elements # returned by unshift print "No of elements returned by unshift: ", unshift(@x, 'Welcome', 'to'); # Array after unshift operation print "\nUpdated array: @x"; Output: Original array: Geeks for Geeks No of elements returned by unshift: 5 Updated array: Welcome to Geeks for Geeks Example 2: Perl #!/usr/bin/perl # Initializing the array @x = (10, 20, 30, 40, 50); # Print the Initial array print "Original array: @x \n"; # Prints the number of elements # returned by unshift print "No of elements returned by unshift: ", unshift(@x, 70, 80, 'Geeks'); # Array after unshift operation print "\nUpdated array: @x"; Output: Original array: 10 20 30 40 50 No of elements returned by unshift: 8 Updated array: 70 80 Geeks 10 20 30 40 50 Example - 3 : Unshifting two lists. Perl #!/usr/bin/perl my @arr_1 = ("is","the","best"); my @arr_2 = ("Geeks","for","Geeks"); unshift @arr_1, @arr_2; print("@arr_1"); Output - Comment More infoAdvertise with us Next Article Perl | reverse() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Perl-Array-Functions Similar Reads Perl | shift() Function shift() function in Perl returns the first value in an array, removing it and shifting the elements of the array list to the left by one. Shift operation removes the value like pop but is taken from the start of the array instead of the end as in pop. This function returns undef if the array is empt 2 min read Perl | sqrt() Function Many times it happens that while solving mathematical expressions we require to calculate the square root of a number. To solve this issue, like other programming language Perl provides us with a built-in function sqrt() which can be used to calculate the square root of a number. Syntax: sqrt value 1 min read Perl | reverse() Function reverse() function in Perl when used in a list context, changes the order of the elements in the List and returns the List in reverse order. While in a scalar context, returns a concatenated string of the values of the List, with each character of the string in the opposite order. Syntax: reverse Li 1 min read 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 | ord() Function The ord() function is an inbuilt function in Perl that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string. Syntax: ord string Parameter: This function accepts a single par 1 min read Perl | chop() Function The chop() function in Perl is used to remove the last character from the input string. Syntax: chop(String) Parameters: String : It is the input string whose last characters are removed. Returns: the last removed character. Example 1: Perl #!/usr/bin/perl # Initialising a string $string = "GfG 1 min read Like