use strict; use warnings; my $abc = "AABCBAABCCCCAB"; my $ab = "AABABAABABABAB"; $abc =~ s/[^ab]/./gi; print "They match!\n" if $ab =~ /^$abc$/i;