http://www.perlmonks.org?node_id=696890


in reply to file parsing

While XML parsing might help a lot if you wanted to process the structure of the file, weeding out stuff between certain markers is a lot easier. I see a classical use case for the flip-flop operator here. You want to copy input to output, skipping some of the input. Seeing certain patterns should switch between the two modes. Perl can do that like this:
#!/usr/bin/perl while (<>) { next if m{^\Q<?xml version="1.0" encoding="UTF-8"?>} ... m{</table>}; print; }
Note the use of \Q to protect a literal string in a regex. The three dots are not something to fill in but precisely three dots here. This is (in scalar context) a flip-flop operator evaluating either the left or the right expression according to its state. To catch beginning and end markers on the same line, you'd have to replace the three dots by two dots. Also look up the -n and the -i switch in perlrun if you like to edit your files in-place with a single short command line.