$fil = 'file.txt'; open(DATA, "$fil") || die "cant open: $!\n"; foreach $line () { if($line =~ /$var/gi) #in this case the variable would be 019 { print "data exists now need to delete it"; s/$var//; #this is not working } } close(DATA);