use strict; # these two lines will save you use warnings; # endless head scratching open(DAT, "text.txt"); # you open this file again in two lines $data_file="; # Assumed this was what the line said close(DAT); foreach $student (@raw_data) { chomp($student); ($name,$roll_no,$class)=split(/\|/,$student); print "The student $name bearing roll number $roll_no is in class $class"; print " \n"; }