in reply to Re^3: While loop with nested if statements
in thread While loop with nested if statements

#!/usr/bin/perl-w use strict; use warnings; my %hash=(); my $key = ''; while(<>){ chomp; if($_ =~ /^>gi.*\[(.+)\]\s>gi.*/){ $key = $1; }else{ $hash{$key} .= $_; } } foreach(keys %hash){ print join("\n",$_,$hash{$_}),"\n"; }
This does what you need