参考《Perl语言入门》的一个正则表达式简单测试程序:
1 #!/usr/bin/perl 2 use warnings; 3 use strict; 4 5 my $pattern=$ARGV[0]; 6 if(not $pattern){ 7 print "Usage: ./ret.pl PATTERN\n"; 8 exit; 9 }10 print "The pattern is m{$pattern}.\n";11 print "Ctrl + D to exit.\n";12 print ">";13 while(){14 chomp(my $line = $_);15 if($line =~ m{ $pattern}){16 print "matched: '$`<$&>$''.\n";17 } else {18 print "not matched.\n";19 }20 print ">";21 }