#!/usr/bin/perl -w use strict; while(<>) { chomp; if (/(\w+a\b)(\w{0,5})/) { print "Matched: |$`<'$1'>'$2'\n"; } else { print "No match: |$_|\n"; } }