print pos($str)-1 while $str =~ /\n/g; print $-[0] while $str =~ /\n/g;