use strict; my $line; while(<>){ chomp; s/^/'/g; s/$/',/g; if($.==1){ s/^/(/;} print $_,"\n"; $line=$_; # this is where I am stuck; I need to test if we are at the last line. }