#Note: To keep Perl from resolving "$\n" as the variable "$\" #followed by the letter "n", this code sample constructs regexen #using non-interpolating quotes. use strict; use warnings; my @aRegexTests =( ["a\n", '^a$', '$ matches boundary, maybe more?'] , ["a\n", '^a$\n' , '$ matches only boundary, \n matches newline' ] , ["a\n", '^a$\z' , '$ matches only boundary, \z fails because of newline?' ] , ["a\n\n", '^a$' , '$ matches only boundary, \n matches first newline' ] , ["a\n\n", '^a$\n' , '$ matches only boundary, \n matches first newline?' ] ); foreach (@aRegexTests) { my ($sString, $sRegex, $sComment) = @$_; my $sMatch = ($sString =~ /$sRegex/) ? "match" : "no match"; my $sPrint = $sString; $sPrint =~ s/\n/\\n/g; print "string=<$sPrint>\n"; print " no modifier: " . "regex=/$sRegex/\n $sMatch => $sComment\n"; $sMatch = ($sString =~ /$sRegex/s) ? "match" : "no match"; print " s modifier (single line mode): " ."regex=/$sRegex/s\n $sMatch => $sComment\n"; $sMatch = ($sString =~ /$sRegex/m) ? "match" : "no match"; print " m modifier (multi line mode): " ."regex=/$sRegex/m\n $sMatch => $sComment\n"; }