open(my $fh,"<","/pathtologfile/logfile.log") or die "can not open the file $!"; my @lines = <$fh>; close($fh); my $count=0; for(my $i=0; $i<=$#lines;$i++) { my @pids = (`ps -ef | grep acuser | grep 2015/01/15 | grep sync_cmd | awk '{print $2}'`) ; } #### #!/usr/bin/perl use strict; use warnings; use Data::Dump qw/ddx/; my ($username,$cmd,$date,$option); sub main(){ system("clear"); system ("cls"); print "************************************************\n"; print "Welcome to Log Grep Tool\n"; print "*************************************************\n"; print "PRESS 1 to grep or any other key to EXIT :"; chomp($option=); if ($option =="1") { getParameters($username,$cmd,$date); viewResults(); } else { print "Goodbye!\n"; exit; } } sub getParameters(){ print "Enter the Username (Eg:auser):" ; chomp($username=); print "Enter the cmd (Eg:sync_cmd):" ; chomp($cmd=); print "Enter the date (Eg:2015/01/14):" ; chomp($date=); return ($username,$cmd,$date); } sub viewResults(){ my @process_ids = (`cat /mnt/accurev_d1/site_slice/logs/acserver.log | grep $username | grep $date | grep $cmd | more`) ; foreach (@pids) { print "$_\n"; } } main();