while (my $line = <>) { croak "I can't handle this crap! '$line'\n" if $line !~ m{\A (foo|bar) }xms; my $dumb_example = $1; .... .... }