use strict; use warnings; my $str = ' '; counttags ($str, 'begin'); sub counttags { my ($test, $target) = @_; my $stag = $test =~ /<$target>/g; my $etag = $test =~ /<\/$target>/g; if($stag != $etag) { print "Number of Start and End tags for element $target does not match"; } } #### Number of Start and End tags for element begin does not match