in reply to Multiple file handling
Scenario: A variable is mentioned in multiple file names and im able to grep once only.
Why should that be the case? That sounds like a rather odd restriction. If you absolutely must work with that restriction, you can do something like
use List::MoreUtils qw/uniq/;
open my $F1, $filename1;
open my $F2, $filename2;
my @files = unique
grep $_-> =~ /$variable/,
(map [$filename1, $_] <$F1>),
(map [$filename2, $_] <$F2>),
Of course that code is much slower and uses much more memory than if you'd just search file by file.