#! perl -sw use strict; local $"='';#" my ($tmp1, $tmp2); for my $lines (0..5) { my $willmatch = ((qq(@{[0..9]}) x 4).$/)x $lines; my $half = int($lines/2); my $wontmatch = ((qq(@{[0..10]}) x 4).$/)x$half . 'X' . ((qq(@{[0..9]}) x 4).$/)x(1+$lines-$half); for ($willmatch, $wontmatch) { # if the number of lines inthe string is less than 4 if( ($tmp1=()=m/\n/mg) <=4 # and they are all < 40 chars and ( $tmp2=()=m/^(?:[^\n]{0,40}\n)/mg ) == $tmp1 ) { print "\nMatches! ($tmp1 lines with $tmp2 < 40 chars)\n"; } else { print "\nNo Match! ($tmp1 lines with only $tmp2 < 40 chars)\n"; } print $_.$/; } } __END__ #### C:\test>200697 Matches! (0 lines with 0 < 40 chars) No Match! (1 lines with only 0 < 40 chars) X0123456789012345678901234567890123456789 Matches! (1 lines with 1 < 40 chars) 0123456789012345678901234567890123456789 No Match! (2 lines with only 1 < 40 chars) X0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 Matches! (2 lines with 2 < 40 chars) 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 No Match! (3 lines with only 1 < 40 chars) 012345678910012345678910012345678910012345678910 X0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 Matches! (3 lines with 3 < 40 chars) 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 No Match! (4 lines with only 2 < 40 chars) 012345678910012345678910012345678910012345678910 X0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 Matches! (4 lines with 4 < 40 chars) 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 No Match! (5 lines with only 4 < 40 chars) 012345678910012345678910012345678910012345678910 012345678910012345678910012345678910012345678910 X0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 No Match! (5 lines with only 4 < 40 chars) 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 No Match! (6 lines with only 4 < 40 chars) 012345678910012345678910012345678910012345678910 012345678910012345678910012345678910012345678910 X0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 C:\test>