#you can use my to declare things even in the middle of a #statement! #the for loop slurps in all the lines in DATAFILE, #provided you have opened it for reading. foreach my $line () { $line =~ s/&+/&/; # you can also use my (...) to declare many variables # at once my ($isbn, $ocln, $title, $author, $call_number) = split(/\t/, $line); # you'll likely have different defaults for cases where # fields are undefined $isbn='' unless defined($isbn); $ocln='' unless defined($ocln); $title='' unless defined($title); $author='' unless defined($author); $call_number='' unless defined($call_number); print NEWFILE "\n"; print NEWFILE ""; print NEWFILE $title, "\n"; print NEWFILE ""; print NEWFILE $isbn, "\n"; #typo? isbn*r* print NEWFILE ""; print NEWFILE $call_number,""; print NEWFILE "\n"; }