in reply to Counting the start and end elements in a line

At least the plus has a special meaning in a regex, therefore you should quote your variables by putting an \Q in front of them (if you want to match the string literally):
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 m +atch"; } }