while ("abc\ndef\nghi" =~ /^(.)/mg) { print("$1\n"); # a,d,g }