#!/usr/bin/perl use strict; use warnings; open my $fh, '<', "input.txt" or die "Can't open the file: $!"; my @words; for my $line (<$fh>){ chomp $line; for my $word (split(/\s+/, $line)){ if ($word =~ /[b-df-hj-np-tv-z]{4}/i){ push @words, $word; } } } print "$_\n" for @words;