#!/usr/bin/env perl use warnings; use strict; open my $test_fh, '<', @ARGV or die "Can not open file $!\n"; while (<$test_fh>) { if ($_ = m/\.|\,|\?/s) { if ($_ = m/it/s) { $part =~ m/it\S+(\.|\,|\?)/s; print "$part\n"; } } } close $test_fh;