#!/usr/bin/perl -l $c .= 1 + int rand 6 for 1 .. 4; # Build up the secret while (<>) { /^\d{4}$|!/ || next; # Check user entered 4 digits $_ .= $c; 1 while s!(.)(.{4})\1!?$2*!s; # Match in right position 1 while s!(\d)(.*\n.*)\1!+$2!; # Match somewhere print /[*+]/g; # Print matches /\*{4}|!/ && exit; }