use strict; # always do so (first thing I learned) my $file = 'database'; my @result; open(INF,$file) || die "Can't open $file: $!\n"; while () { # while walking through file if(/???/) { # if you match your searchstring # you have to replace ??? by a regex push @result,$_; # write current line to array } }