#!/usr/bin/perl use warnings; use strict; print 'Enter a File name: '; chomp (my $file = <STDIN>); die "$file can't be found\n" unless -e $file; print 'Enter a search pattern: '; chomp (my $pattern = <STDIN>); open (F, '<', $file) || die $!; my @lines = <F>; my $cnt = @lines; my $found = 0; foreach my $line (@lines) { print $line and $found++ if $line =~ /\Q$pattern\E/; } print "\nTotal lines matched: $found\n";
In reply to case sensitive addition by Nathan_84
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |