#!/usr/bin/perl use strict; use warnings; my @refnos = (); print "Reading UTR Payment numbers \n"; while(){ chomp; my @data = split(/~/,$_); push(@refnos,$data[1]); # Below grep causing issue next if (grep($data[1] =~ /$_/, @sentUTRs)); # file referenceno.txt will have previously sent $data[1] entries and that file will be read into array @sentUTRs # if $data[1] matches any entry in array @sentUTRs, then we will skip further processing # otherwise , consider this line to do further processing # update $data[1] in file referenceno.txt # referenceno.txt might have 5K or more entries , which are taken into @sentUTRs for comparision with $data[1] in every iteration. } print "Following are the fetched reference no's \n"; foreach (@refnos){ print $_,"\n"; } __DATA__ 0906928472847292INR~UTRIR8709990166~ 700000~INR~20080623~RC425484~IFSCSEND001 ~Remiter Details ~1000007 ~TEST RTGS TRF7 ~ ~ ~ ~RTGS~REVOSN OIL CORPORATION ~IOCL ~09065010889~0906501088900122INR~ 7~ 1~ 1 0906472983472834HJR~UTRIN9080980866~ 1222706~INR~20080623~NI209960~AMEX0888888 ~FRAGNOS EXPRESS - TRS CARD S DIVISI~4578962 ~/BNF/9822644928 ~ ~ ~ ~NEFT~REVOSN OIL CORPORATION ~IO CL ~09065010889~0906501088900122INR~ 7~ 1~ 1 0906568946748922INR~ZP HLHLKJ87 ~ 1437865.95~INR~20080623~NI209969~HSBC0560002 ~MOTOSPECT UNILEVER LIMITED ~1234567 ~/INFO/ATTN: ~//REF 1104210 PLEASE FIND THE DET ~ ~ ~NEFT~REVOSN OIL CORPORATION ~IOCL ~09065010889~0906501088900122INR~ 7~ 1~ 1 0906506749056822INR~Q08709798905745~ 5960.74~INR~20080623~NI209987~ ~SDV AIR LINK REVOS LIMITED ~458ss453 ~ ~ ~ ~ ~NEFT~REVOSN OIL CORPORATION ~IOCL ~09065010889~0906501088900122INR~ 7~ 1~ 1 0906503389054302INR~UTRI790898U0166~ 2414~INR~20080623~NI209976~ ~FRAGNOS EXPRESS - TRS CARD S DIVISI~ ~/BNF/9826805798 ~ ~ ~ ~NEFT~REVOSN OIL CORPORATION ~IOCL ~09065010889~0906501088900122INR~ 7~ 1~ 1