while () { s/\(/\n\(\n/g; s/\)/\n\)\n/g; #do stuff to current line print ">$_<\n" foreach split /\n/; # OR foreach my $t ( split /\n/ ) { print ">$t<\n"; } }