foreach $name ( @pnames ) { chomp($name); #@names = split('need to pass something',$name); # I want to split every input entry into 3 parts- IdentifyingNumber, Name,Version similarly the way they read. $name =~ s/^\s+//; #remove leading spaces $name =~ s/\s+$//; #remove trailing spaces # here logic goes this way, If the version number has matched, serach for name and if name has matched display its identifying number print "Identifying number(say $id) of the packge with name(say $pkg)\n"; }