s/[^[:print:]]/$hash{$&} || '_'/ge; # or # s/[^[:print:]]/exists $hash{$&} ? $hash{$&} : '_'/ge;