my @blocks = do { local $/ = "0000:"; map {chomp;$_} }; #$position = tell(DATA); foreach (@blocks) { chomp; $_ =~ m/(\d+)/g; my $id= $1; if ($_ =~m /Suche:T/g) { foreach my $record(@records) { $xmlID = "ID${id}"; $elt = $record->att('id'); if ($elt eq $xmlID) { my @cats = $record->descendants('data'); foreach $cat(@cats) { $tag = $cat->latt('tag'); if ($tag eq $rtc) { $string = $cat->first_child_text('sub'); } } } } } else { print "e\n"; } } __DATA__ 0000:sf 0002:sff 0003:wqet Suche:T 0000:sf 0002:sff 0003:wqet Suche:T 0000:sf 0002:sff 0003:wqet Suche:T