#!/usr/bin/perl use warnings; use strict; print 'Enter a File name: '; chomp (my $file = ); die "$file can't be found\n" unless -e $file; print 'Enter a search pattern: '; chomp (my $pattern = ); open (F, '<', $file) || die $!; my @lines = ; 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";