Pattern Matching Operators
#Example Meaning
#$name =~ /Tom/ True if $name contains pattern.
# Returns 1 for true, null for false.
#$name !~ /Jack/ True if $name does not contain pattern.
#$name =~ s/Jack/Sam/ Replace first occurrence of John with Sam.
#$name =~ s/Jack/Sam/g Replace all occurrences of John with Sam.
#$name =~ tr/a-z/A-Z/ Translate all lowercase letters to uppercase.
#$name =~ /$pal/ A variable can be used in the search string.
# Using the $_ scalar explicitly
while($_=<DATA>){
print $_ if $_ =~ /I/; # $_ holds the current input line
# print if /I/;
}
__DATA__
S
B
I
N
J
K
Related examples in the same category