sub makepattern { my $str = shift; my @res; for( $i = 0; $i < length( $str ); $i++ ) { push @res, substr( $str, 0, $i ) . "." . substr( $str, $i + 1, length( $str ) - $i ); } return join( "|", @res ); } # example my $imprecisematch = "ABCD"; my $pattern = makepattern( $imprecisematch ); /^($pattern).*\1.*\1$/ #match $_ against three occurrences of this pattern