{ # create a scoping block for slurp-mode reading local $/ = undef; my $str = <>; my $bgnstr = "#:lav\n"; my $bgnlen = length( $bgn ); my $endstr = "#:eof\n"; while ( my $startpos = index( $str, $bgnstr ) >= 0 ) { $startpos += $bgnlen; my $stoppos = index( $str, $endstr, $startpos ); $stoppos = length( $str ) if ( $stoppos < 0 ); my $val = substr( $str, $startpos, $stoppos - $startpos ); print $val; $str = substr( $str, $stoppos ); } }