use strict; use warnings; my @refnos = (); my $old = < undef} grep {chomp; length} <$payments>; close $payments; print "Reading UTR Payment numbers \n"; while () { chomp; my @data = split (/~/, $_); (my $utr = uc $data[1]) =~ s/\s*//g; next if exists $oldPayments{$utr}; $oldPayments{$utr} = $data[1]; print "Payment $utr received of $data[2]\n"; } open $payments, '>', \$old; print $payments join "\n", sort keys %oldPayments, ''; close $payments; print "New payments are:\n "; print join "\n ", grep {defined $oldPayments{$_}} sort keys %oldPayments; __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 #### Reading UTR Payment numbers Payment UTRIN9080980866 received of 1222706 Payment Q08709798905745 received of 5960.74 Payment UTRI790898U0166 received of 2414 New payments are: Q08709798905745 UTRI790898U0166 UTRIN9080980866