On Apr 19, drieux said: >### while(<FH>) { >### if( /^$prefix/ ) { >### print "$_"; >### my $nextLine = $_; >### while ( $nextLine =~ /^$prefix/ ){ >### $nextLine = <FH>; >### print "$nextLine"; >### } >### } >### } # end while
I would follow this code evolution, but partly because I'm a sneaky bastard who delights in finding how to squeeze power out of Perl and do the least work possible myself. First, I'd use a regex trick of //g in scalar context, and /^/m. while (<FH>) { next unless /^$prefix/; $_ .= <FH> while /^$prefix/gm; print; } Sigh. It feels redundant to do that twice. while (<FH>) { if (/^$prefix/) { $next = 1; print; } elsif ($next) { $next = 0; print; } } That feels like it could be a flip-flop. while (<FH>) { print if /^$prefix/ .. !/^$prefix/; } Ta da! If you want to one-line it... /^$prefix/ .. !/^$prefix/ and print while <FH>; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]