use strict; use warnings; my $range_spec = 'A8-15'; # Parse the range spec: my ($tag, $lo, $hi) = $range_spec =~ /(\D+)(\d+)-(\d+)/; # Check the data lines while () { chomp; my ($dtag, $dnum) = /(\D+)(\d+)/; if ($dtag eq $tag and $dnum >= $lo and $dnum <= $hi) { print "$_ matches $range_spec!\n"; } else { print "Mismatch: $_\n"; } } __DATA__ A1 A2 B8 B11 A11 A9 A15 A16