while ( ){ print if /(a+)(b+)/ and length( $1 ) == length( $2 ) - 1; } __DATA__ a b x ab abb abbb aabb aabbb aabbbb ...