use strict; use warnings; my $number = shift; # first usage my @regexp = (); # initialize before first usage, my $regexp[$_] wouldn't work $regexp[$_] = shift foreach (0..$number-1); my @compiled = map qr/$_/, @regexp; # first usage while( my $line = <> ) { # only in block foreach my $pattern (@compiled) { # only in block if( $line =~ /$pattern/ ) { print $line; last; } } } #### my $number = shift( @ARGV ); my @regexp = @ARGV[ 0..$number-1 ];