#!/usr/bin/env perl -w $path = "/foo/bar/baz.pl"; $path =~ s/\//\\/; print "The path is now $path\n"; $path =~ s#/#\\#; print "The path is now $path\n"; $path =~ s/b/B/; print "The path is now $path\n"; #---------------------------------------------------------- #!/usr/bin/env perl -w $path = "/foo/bar/baz.pl"; if ($path =~ /(b\w*)/){ $replace = "\U$1\E"; $path =~ s/b\w*/$replace/; } print "path = $path\n"; $path = "/foo/bar/baz.pl"; while ($path =~ /(b\w*)/){ $replace = "\U$1\E"; $path =~ s/b\w*/$replace/; } print "now, path = $path\n"; #---------------------------------------------- Write a Regular expression that matches a standard United States telephone number (for example: 1-518-276-8988) #----------------------------------------------------------------- #!/usr/bin/env perl -w $string = "This string has many oooooo's"; print "/oo/ match succeeds\n" if $string =~ /oo/; print "/o{2}/ match succeeds\n" if $string =~ /o{2}/; print "/o{2,7}/ match succeeds\n" if $string =~ /o{2,7}/; #What if I want a match to succeed if and only if the string contains #exactly two consecutive o's, no more, no less? #Write a regular expression to do this. #for example, your RegExp succeeds with "foo bar", but not with "fooo bar" #---------------------------------------------------------------------- #!/usr/bin/env perl -w $string = "foo bar aaaaaa baz"; if ($string =~ /(a{2,7})/){ print "match succeeded, \$1 is $1\n"; } else { print "match did not succeed\n"; } if ($string =~ /(a{2,7}?)/){ print "match succeeded, \$1 is $1\n"; } else { print "match did not succeed\n"; }