use strict; use CGI; #use some mail module like MIME::Lite open(Filenm,"filenames.csv") || die "the file is not ready to be opened"; while (){ local $/; # Here the file's size is important, for a lesser size this is ok my @pindigits = split(',',$_); $pinforphonecard = shift(@pindigits); # have the cgi stuff and MIME::Lite or any that you use for mailing part with the $pinforphonecard as the one to be let to send # then go ahead and remove the $pinforphonecard and a comma from the file $_ =~ s/$pinforphonecard,//g; last; }