use strict; use warnings; my $bad_states = { 'bad' => 1 }; { local $/ = ''; my $temp; while () { if (m/{$1}; } if (m/(.*?)<\/task>/) { $temp = $1; ### DO SOMETHING WITH TASK VALUE } } } __DATA__ .... ... .... .... ... .... .... value here ....