my $string = "1\r\n 2 \n"; while ($string = /(.)/g) { print "Encountered character: $1\n"; }