How can i treat the "*" character in $comp as a wildcard for the character at that specific position, so that $string and $comp is considered as equal? In the same way $string and $comp2 should also be considered as equal.

One way would be to substitute the "*" with a "." and do a match, like the following:

Code

print "Same\n" if $string =~ /^ABC.E\z/;

You can see that the match is hard coded, so is not too helpful except to illustrate that the "." in a regex will match any char (almost :). However, the order of strings becomes a bit more complicated when comparing $comp and $comp2, since the latter has to be in // for the matching to succeed.

All of this can be taken care of in a subroutine to which you send any two of these strings to do a comparison test using 'wild-card' characters: