use warnings; use strict; my $test; my @words; open(INFO,"<","testing.pl")||die"Can't open file:$!\n"; chomp (@words=); close(INFO); foreach @words){ if(/^\$ NAME : corry/ .. /\.EON/){ $test=$1; print $test; } }