use strict; use warnings; use 5.010; my $string = "HELLO\nWORLD\nGOODBYE"; my @patterns = ( '\A (.)', #Match start of entire string followed by any char '^ (.)', #Match start of every line followed by any char '(.) \z', #Match any char followed by end of the entire string '(.) $', #Match any char followed by end of a line ); for my $pattern (@patterns) { my @matches = $string =~ /$pattern/gxms; say "@matches"; say '*' x 20; } --output:-- H ******************** H W G ******************** E ******************** O D E ********************