in reply to Read Between the Lines
If your file is small enough (i.e., not many megabytes in size), slurping the whole thing and using a regexp will be efficient enough, and allow you to capture multiple groups, if necessary, without matching unbalanced asterisks.
$_ = do { local $/; <> }; print "Match: $_" for /^\*+$ (.+?) ^\*+$/smxg;
Full example after the <readmore>.
#!/usr/bin/env perl use 5.012; use warnings; use strict; $_ = do { local $/; <DATA> }; print "Match: $_" for /^\*+$ (.+?) ^\*+$/smxg; __DATA__ Here's a text file ********************************** You want the stuff in between the asterisks, which is this sentence. ********************************** ********************************** You probably want this too ********************************** But not this ********************************** Or this either
Output:
Match: You want the stuff in between the asterisks, which is this sentence. Match: You probably want this too
|
|---|