#!/usr/bin/perl use warnings; use strict; ## To chop a sentence at intervals of 4-letter and to print results: my $sentence = "BEAR CALF DEER FEAR GEAR HEAR"; ## To remove blank spaces $sentence =~ s/\s//g; my $output="Words .txt"; open RESULT, '>', $output or do { print "Cannot open file \"$output\".because: $!"; exit; }; print "\n Words are: \n"; foreach my $word ( $sentence =~ /[a-zA-Z]{4}/g ) { print"\n $word: "; print"\n Length of the word = 4\n\n"; print RESULT "\n Words are: \n Word: $word; Length of the word = 4\n\n"; } close RESULT;