#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use diagnostics; undef $/; my $text = ; my @matches; if (@matches = $text =~ /alpha\|([^|]+)\|/smg) { foreach my $match (@matches) { print "match: $match\n"; } } __DATA__ alpha|beta|alpha|theta|alpha|gamma|alpha|episilon #### match: beta match: theta match: gamma #### #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use diagnostics; undef $/; my $text = ; while ($text =~ /alpha\|([^|]+)\|/smg) { print "match: $1\n"; } __DATA__ alpha|beta|alpha|theta|alpha|gamma|alpha|episilon