use strict; use warnings; my $part = 0; while (){ chomp $_; if ( $_ =~ /objet => debut$/ .. /objet => fin$/){ print "TRUE\n"; if ( /objet => debut$/ ){ next; # we skip the opening tag } elsif ( /objet => fin$/ ){ $part++; # we increment our index $part on closing tag } else{ print "\tPART $part: [$_]\n"; # here is the meat: do what you need } } else{ print "FALSE for line: [$_]\n"; } } __DATA__ objet => debut index => 1 a => "premiere valeur" z => "dernier mot" objet => fin ALIEN LINE AFTER fin objet => debut index => 77 a => "autre valeur" z => "aurai-je le dernier mot ?" objet => fin #### TRUE TRUE PART 0: [index => 1] TRUE PART 0: [a => "premiere valeur"] TRUE PART 0: [z => "dernier mot"] TRUE FALSE for line: [ALIEN LINE AFTER fin] TRUE TRUE PART 1: [index => 77] TRUE PART 1: [a => "autre valeur"] TRUE PART 1: [z => "aurai-je le dernier mot ?"] TRUE