#!/usr/bin/perl
my $string = "bl/ah";
# Traditional '/'s: Without the backslash below to escape the forward slash,
# we'll get a runtime error.
print "1\n" if ( $string =~ /bl\/ah/ );
# These work just fine, however.
print "2\n" if ( $string =~ "bl/ah" );
# Note that by using 'm' (match) before the regex, you can use virtually any
# character/brace as a surrounding characters. Without the 'm', you'd hit a
# runtime error in the two matches below:
print "3\n" if ( $string =~ m;bl
/ah
; ); print "4\n" if ( $string =~ m{bl
/ah
} );
# There is also a similar thing for single and double quotes, like the below:
# qq is the double quote (") equivalent:
# q is the single quote (') equivalent.
# Note that \n isn't processed as a new line in single quotes. This is because
# double quotes in perl will process any special characters and variable names
# in the text (so you can include variables inline), and single quotes do not
# for example:
print "\nThe value of \$string in:\n"; # Note the backslash escaped \$ print "Double quotes: $string\n"; print 'Single quotes: $string';
IyEvdXNyL2Jpbi9wZXJsCgpteSAkc3RyaW5nID0gImJsL2FoIjsKCiMgVHJhZGl0aW9uYWwgJy8nczogV2l0aG91dCB0aGUgYmFja3NsYXNoIGJlbG93IHRvIGVzY2FwZSB0aGUgZm9yd2FyZCBzbGFzaCwKIyB3ZSdsbCBnZXQgYSBydW50aW1lIGVycm9yLgpwcmludCAiMVxuIiBpZiAoICRzdHJpbmcgPX4gL2JsXC9haC8gKTsKCiMgVGhlc2Ugd29yayBqdXN0IGZpbmUsIGhvd2V2ZXIuCnByaW50ICIyXG4iIGlmICggJHN0cmluZyA9fiAiYmwvYWgiICk7CgojIE5vdGUgdGhhdCBieSB1c2luZyAnbScgKG1hdGNoKSBiZWZvcmUgdGhlIHJlZ2V4LCB5b3UgY2FuIHVzZSB2aXJ0dWFsbHkgYW55CiMgY2hhcmFjdGVyL2JyYWNlIGFzIGEgc3Vycm91bmRpbmcgY2hhcmFjdGVycy4gV2l0aG91dCB0aGUgJ20nLCB5b3UnZCBoaXQgYQojIHJ1bnRpbWUgZXJyb3IgaW4gdGhlIHR3byBtYXRjaGVzIGJlbG93OgpwcmludCAiM1xuIiBpZiAoICRzd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