my @a = qw( a x z ); my $re = join '', @a; while (<>) { print if /^$re$/; # again, /o might help }