Expanding on blakem's suggestion, here's what I'd do:
#!/usr/bin/perl -w use strict; my ($start, $end) = qw(banana grape); while (<DATA>) { if (/^$start$/ .. /^$end$/) { print unless /^($start|$end)$/; } } __END__ apple banana pear peach grape orange
Update: Thanks to blakem for pointing out the missing $ on the end of the flip-flop. He also points out that this may be a good place to use the /o option to the match operator and I agree. You should probably benchmark to see how much of a gain you get.
--"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: Finding part of a file
by davorg
in thread Finding part of a file
by willa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |