#!/usr/bin/perl use warnings; use strict; my @teststrings = qw(ABCXXXXXX AXCXXXXXX AXXDXFXXX AXXXXXXHI XXXXXXGHI XXXXXXXXX AXXXXXXXI); my $pattern = "ABCDEFGHI"; my $desired_matches = 3; for (@teststrings) { my $result = $pattern ^ $_; my $matches = $result =~ tr/\0/ /; print "$_\n" if $matches == $desired_matches; }