#!/usr/bin/perl -w use strict; my @strs = qw/ a1b2c abcedfg a1q2w3w abcd 1234 12345678901q abcdefghijklmn1 /; foreach my $str ( @strs ) { # "[a-zA-Z]" abbreviated to "\w" and redundant [] removed. if ( $str =~ /^((\w*\d+\w+)|(\w+\d+\w*))\d*$/ && $str =~ /^.{6,12}$/ ) { print "$str = MATCHES\n"; } else { print "$str = No match\n"; } }
Script output wrote: a1b2c = No match abcedfg = No match a1q2w3w = MATCHES abcd = No match 1234 = No match 12345678901q = MATCHES abcdefghijklmn1 = No match
# "[a-zA-Z]" abbreviated to "\w" and redundant [] removed.