use strict; use warnings; my $string = 'XXXXXXXXXXABXXXXXXXXX'; my ($match) = $string =~ m/X{10}([AB]{2})X{9}/; print $match;