in reply to Regex to dereference

regexps are fine on their own for one-off use, but for iterative use they are often better wrapped up into a parser, e.g.:
#untested use myParser; my %CSV = ('n' => 'n', 't' => 't', 'f' => 'f', '\\' => '\\', ); $_ = '\\\\\\\\\\'; my ($result,$status) = parse( LEXICON=>\%CSV ); package myParser; sub new { my $self = Interface( @_ ); my $class = ref( $self ) || $self; return (bless $self), $class; } sub parse { my $self = Interface( @_ ); my $bufadr = ($self -> { BUFREF } ||= \$_); # default buffer $_ my $lexicon = $self -> { LEXICON } or die; my $return = []; my $lexStatus = 1; while( length( $$bufadr ) && lexStatus ) { Throw( $self ); my $content; ( $content, $lexStatus ) = AntiLex( $self, keys %$lexicon ); $lexStatus and push @$return, $content; } return $return, $lexStatus; } sub Throw { AntiLex( shift(), '\S' ); } sub AntiLex { my $self = shift; my $bufadr = $self -> { BUFADR }; my $status; for my $pattern ( @_ || die() ) { if ( $$bufadr =~ /^\n*($pattern)(.*)$/m ) { $$bufadr = $2; return ( $1, 1 ); } } return ( undef(), 0 ); } sub Interface { return ( ref( $_[0] ) || !$#_ ) ? shift() : { @_ }; } 1;

-M

Free your mind