#!/usr/bin/perl # Can be used to test regular expressions. # Provide the regular expression in the command line, # and then type strings, each of which will be checked # against the regular expression for a match. # To terminate, type EOF (cntl/Z or cntl/D). # Note that $' goes in and out of scope from if to while. # Replace $leftover with $' in the print after the while, # and see the difference... $leftover = ''; while( ) { chomp; if( /$ARGV[0]/ ) { print "Matched: |$`<$&>"; $leftover = $'; while( $' =~ /$ARGV[0]/ ) { print "$`<$&>"; $leftover = $'; } print "$leftover|\n"; } else { print "No match.\n"; } }