#/usr/bin/perl use 5.010; while(<>){ chomp; if (/YOUR_PATTERN_GOES_HERE/) { say "${^PREMATCH}|${^MATCH}|${^POSTMATCH}"; } else { say "No match: |$_|\n"; } }