On Tue, 10 Nov 2009, at 14:37:59, Philip Newton wrote: >But you could try this: > >sub parse >{ > my ( $text, $re ) = @_; > my @matches = $_[0] =~ /^$re// or die "Expected $re in $text...\n"; > $_[0] =~ s/^$re//; > > return @matches >} > >at the cost of running the regexp twice (once for matching and >capturing, then once for substituting). > >Cheers, >Philip Capturing and substituting in one step. #------------------------------------------------- sub Parse { my @matches = (); use re 'eval'; $_[0] =~ s/($_[1])(?{push(@matches, $1)})//g; return @matches; } #------------------------------------------------- Torsten