#!/usr/bin/perl; use strict; # I have the text file named as data.txt. my $infile = 'data.txt'; # Now i like to read the line from data.txt open IN,'<',$infile or die "$!"; print "Reading from '$infile'\n"; my $dir; while (){ chomp; # in which the line # starts with ZERO # contains the directory path? if (/^ZERO:(.*)/){ $dir = $1; } } close IN; print "Directory is '$dir'\n";