open(FILEHANDLE,"+< $FILENAME) or die print $!; while(){ if ($_ ne 'b|b|b|b|b|b'){ push(@outtext,$_); } Do what you want from here. Of course it always a good idea to lock the file if you are on a UNIX system.