$_ = 'And the man said: "Let there be music!"'; while(1) { /\G\s*(?=\S)/gc or last; if(/\G(\w+)/gc) { print "Found a word: $1\n"; } elsif(/\G(['"])/gc) { print "Found a quote: $1\n"; } elsif(/\G([.,;:!?])/gc) { print "Found punctuation: $1\n"; } else { /\G(?=(\S+))/gc; die sprintf "Don't know what to do with what I found next: %s (position %d)", $1, pos; } } print "Parsing completed successfully.\n";