$s = "foo\nfoot\nroot"; $s =~ /^foo/g; # matches only the first foo $s =~ /^foo/gm; # matches both foo $s =~ /f.*t/g; # matches only foot $s =~ /f.*t/gs; # matches foo\nfoot\nroot $s =~ /f.*?t/gs; # matches foo\nfoot $s =~ /^foot.*root$/g; # doesn't match $s =~ /^foot.*root$/gm; # doesn't match $s =~ /^foot.*root$/gs; # doesn't match $s =~ /^foot.*root$/gms; # matches foot\nroot