1. String Functions
length
Returns the length of a string.
my $str = "Hello, World!";
my $len = length($str);
print "Length: $len\n";
substr
Extracts a substring from a string.
my $str = "Hello, World!";
my $sub = substr($str, 0, 5);
print "Substring: $sub\n";
index
Returns the position of a substring within a string.
my $str = "Hello, World!";
my $pos = index($str, "World");
print "Position: $pos\n";
rindex
Returns the last position of a substring within a string.
my $str = "Hello, World! World!";
my $pos = rindex($str, "World");
print "Last Position: $pos\n";
uc
Converts a string to uppercase.
my $str = "Hello, World!";
my $uc_str = uc($str);
print "Uppercase: $uc_str\n";
lc
Converts a string to lowercase.
my $str = "Hello, World!";
my $lc_str = lc($str);
print "Lowercase: $lc_str\n";
ucfirst
Converts the first character of a string to uppercase.
my $str = "hello, world!";
my $ucfirst_str = ucfirst($str);
print "Ucfirst: $ucfirst_str\n";
Read more »Labels: Perl Built-ins Quick Reference