open(IN, "/some/file") || die "Cant open /some/file: $!\n"; while () { push(@foo, $_) if ( m/^$match/ ); } close(IN); # as opposed to open(IN, "/some/file") || die "Cant access /some/file: $!\n"; @foo = grep(m/^$match/, ); close(IN);