if ( /ABC(...).E/ and 2 <= ( $1 =~ tr/D// )) { # get here when the captured region contains 2 or 3 D's } #### if ( /D (.{3}) [A-Z]{3,15} (\d{6,8}) [^D]{2}/x and 2 <= ( $1 =~ tr/F//) # first capture contains at least two F's and 3 <= ( $2 =~ tr/1//) # second capture contains at least three 1's ) { # get here when all conditions are met }