#!/usr/bin/perl use warnings; use strict; print 'Enter a File name: '; chomp (my $file = ); print 'Enter a search pattern: '; chomp (my $pattern = ); open (my $fh, '<', $file) or die "Unable to open '$file' for reading: $!"; my $found = 0; while (<$fh>) { if (/\Q$pattern\E/i) { print; $found++; } } print "\nTotal lines matched: $found\n";