#!/usr/bin/perl use warnings; use strict; foreach ('A000' .. 'B999') { print "$_ "; if (/^(?: A(?:000|12[3-9]|1[3-9]\d|[2-3]\d\d|4[0-4]\d|45[0-6]|999) | B(?:000|789|79\d|8[0-7]\d|88[0-8]) )$/x) { print "match\n"; } else { print "does not match\n"; } } #### my %match; my @num = ('A000','A123'..'A456','A999','B000','B789'..'B888'); @match{ @num } = (); foreach my $key('A000' .. 'B999') { print "$key "; if ( exists $match{$key} ) { print "match\n"; } else { print "does not match\n"; } }