use DB_File ; tie %h, "DB_File", $dbFname ; while( <$f> ) { if( exists $h{$_} ) { # equal lines in file } $h{$_} = 1 ; # or some piece of data }