use strict; use warnings; use 5.010; my $pattern = 'x[ABC]'; my @strings = ( 'xA', 'xB', 'xC', 'xY', ); for (@strings) { if (/$pattern/) { say; } } --output:-- xA xB xC