in reply to Comparing strings

You want to make sure that the whole string matches and not just a substring. You can use the "anchors" ^ (start of string) and $ (end of string) for that:

if($a[$i] =~ /^$b[$j]$/i)

But if you want to compare the whole string, a direct comparison of the upper case variants is more straightforward:

if(uc $a[$i] eq uc $b[$j]) { ... }

Replies are listed 'Best First'.
Re^2: Comparing strings
by ikegami (Patriarch) on Jul 24, 2006 at 15:06 UTC

    Does @b contain regexp or strings? If it contains regexps, your second snippet doesn't work. If it contains strings, your first snippet is broken. Sounds like @b contains strings, so the solutions would be

    if ($a[$i] =~ /^\Q$b[$j]\E\z/i)

    and (the much faster)

    if (uc $a[$i] eq uc $b[$j])

    You can only omit the quoting provided by \Q...\E is you are sure @b doesn't contains any meta characters.