# File: match1.pl # Title: Take all groups of n chars from a string (non-overlapping) # $s =~ m/(.{$n})/g; # means match(m) first n chars .{$n} - that is repeat . n times # () means set result in variable $1 # g - globally will find all solutions by turn # Author: Mihaela Malita # Input string? bioinformatics # Input integer? 3 # Groups of n chars from the string: # bio # inf # orm # ati $yesorno = 'y'; while ($yesorno eq 'y') { print "Input string? "; $s = ; chop($s); print "Input integer? "; $n = ; chop($n); print("Groups of n chars from the string:\n"); while ( $s =~ m/(.{$n})/g ) { # each time variable $1 takes the value of the match print $1, "\n"; } print("\nContinue(y/n)? "); $yesorno = ; chop($yesorno); } print "Bye"; exit;