while (<>) { next if !/^\${4}/; my $next_line = <>; # do something }