If you split on the blank lines instead of on newlines then you don't have to go back:
#!/usr/bin/env perl use strict; use warnings; my $input = qq# PEM 0: PEM 1: PEM 2: State: Online PEM 3: State: Online #; for my $rec (split /\n\n/, $input) { next unless $rec =~ /State:\s+Online/; $rec =~ /(PEM \d+)/ or die "Bad input: no PEM in '$rec'!"; print "$1 is online\n"; }
In reply to Re: Regular expression query
by hippo
in thread Regular expression query
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |