Я бы создал бесконечный цикл while
для выхода из:
#!/usr/bin/env perl
use strict;
use warnings;
my @words = qw(Hi world thanks);
foreach my $word (@words) {
print "Enter a line with word: $word\n";
while (1) {
chomp( my $input = <STDIN> );
if( $input=~/$word/i ) {
print "Great\n";
last;
} else {
print "Incorrect. Type a line contaning $word\n";
}
}
}
Конечно, я бы, вероятно, разделил логику каждого отдельного слова в подпрограмму, а затем зациклил бы на этом:
#!/usr/bin/env perl
use strict;
use warnings;
my @words = qw(Hi world thanks);
get_word($_) for @words;
sub get_word {
my $word = shift or die "Need a word";
print "Enter a line with word: $word\n";
while (1) {
chomp( my $input = <STDIN> );
if( $input=~/$word/i ) {
print "Great\n";
last;
} else {
print "Incorrect. Type a line contaning $word\n";
}
}
}