use strict; use warnings; my $file = 'text.txt'; open my $fh, '<', $file or die "can not open $file: $!"; while (<$fh>) { chomp; my ($name, $roll_no, $class) = split /\|/; print "The student $name bearing roll number $roll_no is in class $class\n"; } close $fh;