#!/usr/bin/perl use strict; use warnings; my(@lines, $line); print "\n\tUsing tr\n"; @lines = ; for $line(@lines) { chomp $line; my $line1 = $line; if ( ($line1 =~ tr/[r|R]/r/) == 4 ) { # Case insensitive print "$line1\n"; } } print "\n\t using match:\n"; for $line(@lines) { if ( $line =~ / ^ # start at beginning of line ([^rR]*) # 0 or more non-r chars r # match "r" ([^rR]*) # negative lookahead, 0 or more non-r chars r ([^rR]*) # alternately, could be ?=[^r]* r ([^rR]*) r ([^rR]*) $ # end of line /ix) { # extended syntax; end of match; end of condition print "$line\n" } } print "\n\t using match2:\n"; for $line(@lines) { if ( $line =~ /^([^r]*|[^R]*)r([^r]*|[^R]*)r([^r]*|[^R]*)r([^r]*|[^R]*)r([^r]*|[^R]*)$/i) { print "$line\n"; } } print "\n and the data is:\n"; for $line(@lines) { print $line . "\n"; } print "\nDone\n"; __DATA__ There are four "r"s in this sentence. 4 This one has how many? 0 None in this. 0 But where can there be as many words with 'r's as there are here? 7 Still, rrrr makes no sense. 4 Drill for sentences with multiple instances of "are" and "were" regularly. 5 There are four "r"s in this sentence. 4 This one has how many? 0 None in this. 0 But where can there be as many words with 'r's as there are here? 7 Still, rrrr makes no sense. 4 Drill for sentences with multiple instances of "are" and "were" regularly. 5 Argh. Right you are, Randy! 4 matches if insensitive (but only 2 match when case sensitive). #### Using tr There are four "r"s in this sentence. 4 Still, rrrr makes no sense. 4 There are four "r"s in this sentence. 4 Still, rrrr makes no sense. 4 Argh. right you are, randy! 4 matches if insensitive but only 2 match when case sensitive. using match: There are four "r"s in this sentence. 4 Still, rrrr makes no sense. 4 There are four "r"s in this sentence. 4 Still, rrrr makes no sense. 4 Argh. Right you are, Randy! 4 matches if insensitive but only 2 match when case sensitive. using match2: There are four "r"s in this sentence. 4 Still, rrrr makes no sense. 4 There are four "r"s in this sentence. 4 Still, rrrr makes no sense. 4 Argh. Right you are, Randy! 4 matches if insensitive but only 2 match when case sensitive. and the data is: ....