in reply to Search a text and output to different text files

This assumes that your search text won't be across different lines.

open SEARCH, $file_to_search or die $!; my $count = 1; while (<SEARCH>) { if (/$regex_to_search_for/) { open FOUND, '>', "found$count.txt" or die $!; print FOUND $_; ++$count; } }
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.