while() my $ok = 0; for my $tag ( @tags ) $ok = /^\s*(\<$tag\>)(.*)$/ and last; } $ok or die "Incorrect entry $_"; # $1 is now the tag, $2 the rest of the line # ... }