my $line; open FH,"file.ext" or die $!; $line=$_ while(); close FH; #now the last line is in $line my($id)=split(/\|/,$line); #now you can use $id+1 #### my $id; open FH,"file.ext" or die $!; while(){ my($nid)=split(/\|/); $id=$nid if $nid>$id; } close FH; #and again you use $id+1