Perl String Functions



There are a lot of Perl string functions available in Perl which let you perform different operations on strings and scalars.

Some of these functions allow you to find the string’s length, get a substring or the position of a substring in a string, change the case of the characters in the string, to mention only some of them.

In calling these functions, if no argument variable is specified, the respective function will use by default the special variable $_.


Click Below to See the Best

Perl How-to Snippet Collection

and Save Hours of Surfing on Internet!


We’ll shortly describe below some of the most frequently used Perl string functions:

chompremoves trailing newlines and returns the number of characters removed
chopremoves and returns the last character from a string
chrconverts ASCII or Unicode values into their corresponding characters
cryptallows you to store passwords or other sensitive data using ASCII characters as encrypted strings
hexconverts a hex string into the numerical corresponding value
indexreturns the position of the first occurrence of a substring in a string
lcconverts all the characters of a string in lowercase and returns the new string
lcfirstconverts the first character of a string in lowercase and returns the new string
lengthreturns the number of bytes/characters in a string
octconverts an octal string into the numerical corresponding value
ordconverts a character into its ASCII/Unicode corresponding value
packconverts a list into a string, according to a user-defined template (ex. a binary representation of a list)
q/STRING/singly quote a string
qq/STRING/doubly quote a string
reversein scalar context, concatenates the elements of a list and returns a string value with all characters in the opposite order
rindexis similar to index, but returns the position of the last occurrence of a substring in a string
sprintfemulates the C sprintf function
substrextracts a substring from a string and returns it
tr///transliterate a string
ucconverts all the characters of a string in uppercases and returns the new string
ucfirstconverts the first character of a string in uppercase and returns the new string


A-N-Y-O-N-E Can Learn and Master Perl!
And That Includes YOU!


Check these how-to tutorial eBooks (PDF format):


Table of Contents:

A Perl Script
Install Perl
Running Perl
Perl Data Types
Perl Variables
Perl Operators
Perl Lists
Perl Arrays
    Array Size
    Array Length
Perl Hashes
Perl Statements
    Perl if
    Perl unless
    Perl switch
    Perl while
    Perl do-while
    Perl until
    Perl do-until
    Perl for
    Perl foreach
Built-in Perl Functions
    Functions by Category
        String Functions (more)
        Regular Expressions and Pattern Matching
        List Functions
        Array Functions
        Hash Functions
        Miscellaneous Functions
    Functions in alphabetical order
        chomp
        chop
        chr
        crypt
        defined
        delete
        each
        exists
        grep
        hex
        index
        join
        keys
        lc
        lcfirst
        length
        map
        oct
        ord
        pack
        pop
        push
        q
        qq
        qw
        reverse
        rindex
        scalar
        shift
        sort
        splice
        split
        sprintf
        substr
        tr
        uc
        ucfirst
        undef
        unpack
        unshift
        values

return from Perl String Functions to Perl Basics



Would you like to create your own website like this one?
Hit the Alarm Clock!

Site Build It!