while () { my $reading = 0; $reading++ if $reading; if(/.* ss:Name=\"$file*/oi){ # When we see start storing the data print "VALUE IS $value \n"; $reading = 1; } $reading = 0 if (//); next unless $reading; print "$_"; }