#! perl use strict; use warnings; my $text = < 'fox.+?jumps', 'B' => '(?s)fox.+?jumps' ); my %functions = ( '1. no' => \&no_mod, '2. qr//' => \&qr_mod, '3. late' => \&late_mod, '4. inline' => \&inline_mod ); foreach my $search_key (sort keys %searches) { print "\nSearching on '$searches{$search_key}':\n\n"; foreach my $fn_key (sort keys %functions) { printf "%s%-9s 's' modifier: %s\n", $search_key, $fn_key, $functions{$fn_key}->($text, $searches{$search_key}) ? 'Match found' : 'No match'; } } sub no_mod # no 's' modifier { my ($string, $pattern) = @_; my $regex = qr/$pattern/; return ($string =~ /$regex/); } sub qr_mod { my ($string, $pattern) = @_; my $regex = qr/$pattern/s; # <= 's' modifier return ($string =~ /$regex/); } sub late_mod { my ($string, $pattern) = @_; my $regex = qr/$pattern/; return ($string =~ /$regex/s); # <= 's' modifier } sub inline_mod { my ($string) = @_; return ($string =~ /fox.+?jumps/s); # <= 's' modifier } __END__ #### Searching on 'fox.+?jumps': A1. no 's' modifier: No match A2. qr// 's' modifier: Match found A3. late 's' modifier: No match A4. inline 's' modifier: Match found Searching on '(?s)fox.+?jumps': B1. no 's' modifier: Match found B2. qr// 's' modifier: Match found B3. late 's' modifier: Match found B4. inline 's' modifier: Match found