#!/usr/bin/perl #use strict; use warnings; sub search_pattern { my $file_name = $_[0]; my $search = $_[1]; open(LOGFILE, $_[0]) or die("Error: cannot open file '$_[0]'\n"); while () { if ( $_ =~ /$search/ ) { my $val = $`; #Matches Everything after pattern $val =~ s/^\s+//; #remove leading spaces $val =~ s/\s+$//; #remove trailing spaces $val =~ s/\D//g; #Just has the digits. All other charcters are filtered. #print "$val\n"; print "\nFirst Occurence:$val \n"; my $line = $.; print "Line number:$line\n"; #$temp = $line; #print "$temp"; #print "$."; last; } } } my $file_n ="test.txt"; my $search_p = "This is phrase 2"; &search_pattern($file_n, $search_p);