fork(1) download
  1. #!/usr/bin/perl
  2.  
  3. my $string = "bl/ah";
  4.  
  5. # Traditional '/'s: Without the backslash below to escape the forward slash,
  6. # we'll get a runtime error.
  7. print "1\n" if ( $string =~ /bl\/ah/ );
  8.  
  9. # These work just fine, however.
  10. print "2\n" if ( $string =~ "bl/ah" );
  11.  
  12. # Note that by using 'm' (match) before the regex, you can use virtually any
  13. # character/brace as a surrounding characters. Without the 'm', you'd hit a
  14. # runtime error in the two matches below:
  15. print "3\n" if ( $string =~ m;bl/ah; );
  16. print "4\n" if ( $string =~ m{bl/ah} );
  17.  
  18. # There is also a similar thing for single and double quotes, like the below:
  19. # qq is the double quote (") equivalent:
  20. print qq/test\n/;
  21. # q is the single quote (') equivalent.
  22. print q/test\n/;
  23.  
  24. # Note that \n isn't processed as a new line in single quotes. This is because
  25. # double quotes in perl will process any special characters and variable names
  26. # in the text (so you can include variables inline), and single quotes do not
  27. # for example:
  28. print "\nThe value of \$string in:\n"; # Note the backslash escaped \$
  29. print "Double quotes: $string\n";
  30. print 'Single quotes: $string';
Success #stdin #stdout 0s 3608KB
stdin
Standard input is empty
stdout
1
2
3
4
test
test\n
The value of $string in:
Double quotes: bl/ah
Single quotes: $string