#!/usr/bin/perl while( ) { chomp; print "$_ matches!\n" if /^a.+(f|g)$/; } __DATA__ axxxi bxg cxxf axxxh axxxg axxxf