#!/usr/bin/perl -w use strict; open (FILE,"abc345.txt") or die $!; while (){ $_ =~ /((^Query = .*)|(^\>.*)|(Length = .*))/i; print $1 // "no match", "\n"; print $2 // "no match", "\n"; print $3 // "no match", "\n"; print $4 // "no match", "\n"; } close (FILE) ;