#!/usr/bin/perl
use strict;
use warnings;
while(<>){
chomp;
#if(/YOUR_PATTERN_GOES_HERE/){
#if(/match/){
if(/a/){
print "Matched: | $`<$&>$'|\n";
}
else{
print "No match: |$_|\n";
}
}
运行脚本命令 #/bin/perl test.pl text.txt
#!/usr/bin/perl
use strict;
use warnings;
while(<>){
chomp;
#if(/YOUR_PATTERN_GOES_HERE/){
#if(/match/){
if(/a/){
print "Matched: | $`<$&>$'|\n";
}
else{
print "No match: |$_|\n";
}
}