sub counttags { my $stag=0; my $etag=0; my $tag = quotemeta($_[0]); while ($_ =~ /<$tag]>/g) {$stag++} while ($_ =~ /<\/$tag>/g) {$etag++} if($stag != $etag) { print "Number of Start and End tags for element $_[0] does not match"; } }