in reply to Number of digits at the end of the string

If I understand your requirements correctly, the following should work. (It works with your example strings as you have provided.)

use strict; my @strings = qw(aaa_gjh1_dfgdf_0009 aaa_gjh_0000 aaa_fdsfs_000 aaa_sd +f_jdsh_01111); foreach my $test (@strings) { if($test =~ /^aaa_[a-z0-9_]{1,23}[a-z_][0-9]{4,4}$/){ print "Match---\n"; } else{ print "No Match... :(\n"; } }
memnoch