use strict; use warnings; use DDD::test2; my $incr = 0; my @array=""; undef $/; open DATA, "san.txt" or die $!; my @blocks = map { [ split /\n/ ] } ( split /(?=ITEM NO:)/, ( map { s/\#.*\n//; $_ } )[0] ); while(1) { @array = @{ $blocks[$incr] }; if (@array eq "") { print "There is no item remaining in the file"; last; } test2::REQUEST(@array); $incr++; } #test2.pm contains package test2; sub REQUEST (@) { my @array=@_; print "@array\n"; } 1; #Suppose san.txt file contains #This is the ITEM file #This is a perl config file # I am ok ITEM NO:1 [aaa] 111 ffff [bbb] 222 [ccc] 333 #This not taken ITEM NO:2 [ddd] 444 [eee] 555 0000 [fff] 666 #This is not taken ITEM NO:3 [ddd1] 4441 [eee1] 5551 [fff1] 6661 # I am sanjay ITEM NO:4 ... ... ...