use strict; use warnings; use Data::Dumper; my ($str,@match); $str = " foo bar baz "; @match = $str =~ /(foo.*bar)/; # nope! print Dumper \@match; @match = $str =~ /(foo.*bar)/m; # nope! print Dumper \@match; @match = $str =~ /(foo.*bar)/s; # this one! print Dumper \@match; $str = " foo bar foo baz "; @match = $str =~ /^(foo bar)/; # nope! print Dumper \@match; @match = $str =~ /^(foo bar)/s; # nope! print Dumper \@match; @match = $str =~ /^(foo bar)/m; # this one! print Dumper \@match;