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