$ perl -wle ' $a = "a\nb"; print $1 while $a =~m/^(.)/g' a $ perl -wle ' $a = "a\nb"; print $1 while $a =~m/^(.)/gm' a b