#!/usr/bin/perl while(<>) { chomp; print "\"$1\" was matched out of \"$_\"\n" if m/(\w{5}?)/; }