while ( my $line = ) { my @items = split "!CR!", $line; if ( expected ( @items ) ) { print join "\n", @items; } } # This would be need to be done to taste sub expected { my @data = @_; my $matched = 0; # Say you need to make sure the id line is there... foreach my $item ( @data ) { if ( $item =~ /^id\[\d+\]/ ) { $matched++; last } } return $matched; }