use strict; use warnings; my $found = ''; while(){ chomp; if($_=~ /^\.\.AU:$/) { $found = 'AU'; next; } if($found eq 'AU'){ print "\n".$_; } if($_=~ /^\.\.BD:$/) { $found = 'BD'; next; } if($found eq 'BD'){ print ','.$_; } $found = ''; } #### my $tag; while(){ chomp; if(/([A-Z]{2}):$/){ $tag = $1; next; } if($tag eq 'AU'){ print "\n".$_; } if($tag eq 'BD'){ print ','.$_; } }