my $prefix = 'abc'; my $endingLetters = '0pz'; if (/$prefix[$endingLetters]/){...}