I would use
grep, but remove the
and $filter_clean from inside its condition. If you really want to check it, do it just once before running grep, repeating it when the variable does not change is useless. Also,
map returns a list, but you want to concatenate a string, so use
join. If you add numbers to your
%filter_map (e.g. by
$filter_map{$_} = $_ for 0 .. 9;
), you can simplify it to
$filter .= join q{}, map $filter_map{ uc $_ }, split //, $filter_clean
+;
which seems pretty clear to me.